tween.js icon indicating copy to clipboard operation
tween.js copied to clipboard

fix: when yoyo repeats, first frame behaves as if yoyo=false

Open humodz opened this issue 1 year ago • 0 comments

fix for https://github.com/tweenjs/tween.js/issues/677

summary:

The current logic first updates the properties, then run the logic that reverses the start and end values for yoyos. The problem is that if the tween has just started repeating, the update will happen before the reversing, so for a single frame the value will be wrong, as if yoyo=false

The proposed fix is to check if the tween has just started to repeat and, if so, apply the yoyo logic before updating the properties

		if (elapsedTime <= this._duration) {
			doUpdates();
			stillPlaying = checkStillPlaying();
		} else {
			stillPlaying = checkStillPlaying();
			doUpdates();
		}

Also, something that I noticed, but I'm not sure if it's intended or not: when the tween repeats, onEveryStart seem to trigger one update later than I would expect. For example:

new TWEEN.Tween(obj)
    .to({ x: 100 }, 100)
    .repeat(1)
    .yoyo(true)
    .start(0);

TWEEN.update(99); // start everystart update
TWEEN.update(120); // update repeat
TWEEN.update(150); // everystart update
TWEEN.update(199); // update
TWEEN.update(201); // update complete

shouldn't everystart happen at 120ms, since the tween has already repeated at that instant?

humodz avatar Feb 12 '24 09:02 humodz