Pausing a tween from a Group removes that tween from the Group's array.
I'm not sure if that was intentional, but when we access the array of tweens from a Group using .getAll() and execute .pause() on one, that tweens gets removed from that Group's tween array. I find that weird as pausing a tween should not remove it. I understand if we did a .stop() on it that it would get terminated, but not .pause().
Also, it would be nice to have a .pauseAll() function to be used on a Group. Obviously, we can access the array of tweens, but like the issue I brought up, pausing each tween removes them completely.
This seems unintuitive indeed, so will mark as a bug. Do you have a sample? Here's a starting point: https://codepen.io/trusktr/pen/OJRQjZw
Not sure if this small code was required, but here is the demonstration that the tween from a Group's array gets removed after pausing a tween:
const DATA = { 'X': 0 };
const TWEEN_DATA = { 'X': 1000 };
const TWEEN_GROUP = new TWEEN.Group();
new TWEEN.Tween(DATA, TWEEN_GROUP).to(TWEEN_DATA).duration(1000).onUpdate(UpdateCallback).start();
function UpdateCallback() {
console.log(DATA);
}
function Animate() {
requestAnimationFrame(Animate);
TWEEN_GROUP.update();
}
Animate();
setTimeout(function () {
console.log('Array Length Before Pausing: ' + TWEEN_GROUP.getAll().length);
TWEEN_GROUP.getAll()[0].pause();
console.log('Array Length After Pausing: ' + TWEEN_GROUP.getAll().length);
}, 500);
Yeah, totally I see that. I meant, do you have an example of a problem this is causing?
Even long ago before TWEEN was made into a Group, and before there was pause(), Tweens were added or removed on start/stop:
https://github.com/tweenjs/tween.js/blob/cbc0df91a7825f3fcba2ef8a6b83a1ece9fc34e1/src/Tween.js#L10
So we need to see an example of the problem.
I found a code related to this issue.
https://github.com/tweenjs/tween.js/blob/e01bbdbebe2d05509b73bbbe7dc7438228124a9e/src/Tween.ts#L284-L285
https://github.com/tweenjs/tween.js/blob/e01bbdbebe2d05509b73bbbe7dc7438228124a9e/src/Tween.ts#L301-L302
All tween instances hold a reference to a group. On pause, tween removes itself from a group and re-adds itself on resume.
https://github.com/tweenjs/tween.js/blob/e01bbdbebe2d05509b73bbbe7dc7438228124a9e/src/Tween.ts#L393-L394
Tween.update() skips paused tween. Because of this, it is not necessary to remove and re-add tweens to a group.
The downside of this behavior is that it can be confusing when users use Group to manage and manipulate their tween.
The advantage of this behavior is that the update loop is faster if the mainGroup holds a large number of paused tween.
Ah indeed, should be easy to implement!
hmmm, it looks like this Group issue has not been resolved yet or this is not really a bug
Yeah, hasn't been resolved yet. I'd still classify it as a bug because if a tween is added to a group but then it does not appear in the group, that break people's expectations.
I believe it is more correct that if a tween is added to a group, it is always visible in the group's array of tweens.
@NyaNguyen Did you have a use case where you were looking in the array and your code did not work as expected because the tween was not there?
Today's v24.0.0 release changed this so that starting, pausing, or stopping a tween no longer automatically adds/removes the tween to/from its group.
More details in the release notes:
https://github.com/tweenjs/tween.js/releases/tag/v24.0.0