Skip to content

Commit

Permalink
fix: implement fix from @benfoxall for 'chained tweens get out of syn…
Browse files Browse the repository at this point in the history
…c with sporadic updates'. Closes #187
  • Loading branch information
sole committed Sep 29, 2015
1 parent 42387a9 commit 37dccbe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ TWEEN.Tween = function (object) {
}

for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) {
_chainedTweens[i].start(time);
// Make the chained tweens start exactly at the time they should,
// even if the `update()` method was called way past the duration of the tween
_chainedTweens[i].start(_startTime + _duration);
}

return false;
Expand Down
24 changes: 23 additions & 1 deletion test/unit/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,29 @@
test.equal( TWEEN.getAll().length, 0 );
test.done();

}
},

'Test TWEEN.Tween.chain progressess into chained tweens': function(test) {

var obj = { t: 1000 };

// 1000 of nothing
var blank = new TWEEN.Tween({}).to({}, 1000);

// tween obj.t from 1000 -> 2000 (in time with update time)
var next = new TWEEN.Tween(obj).to({ t: 2000 }, 1000);

blank.chain(next).start(0);

TWEEN.update(1500);
test.equal(obj.t, 1500);

TWEEN.update(2000);
test.equal(obj.t, 2000);

test.done();

},

};

Expand Down

0 comments on commit 37dccbe

Please sign in to comment.