TweenData now caches the start/end values to avoid re-calc on replay.

This commit is contained in:
Richard Davey 2017-05-18 02:21:40 +01:00
parent 320594294f
commit 8d7629a4ab
5 changed files with 34 additions and 5 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '5ba7bc90-3b63-11e7-9031-4dab81ef32d2'
build: 'fca5b270-3b66-11e7-9105-d95f13cc676f'
};
module.exports = CHECKSUM;

View file

@ -41,6 +41,10 @@ var TweenData = function (value, ease, delay, duration, hold, repeat, repeatDela
// TWEEN_CONST.CREATED
state: 0,
// store start and end values so we don't calc them on every play through
startValue: null,
endValue: null,
// For chained TweenData these point to the prev and next references
prev: null,
next: null

View file

@ -1,8 +1,24 @@
var LoadValues = function ()
{
this.start = this.target[this.key];
var tweenData = this.currentTweenData;
if (tweenData.startValue === null)
{
this.start = this.target[this.key];
this.end = this.currentTweenData.value();
tweenData.startValue = this.start;
tweenData.endValue = this.end;
}
else
{
this.start = tweenData.startValue;
this.end = tweenData.endValue;
}
this.current = this.start;
this.end = this.currentTweenData.value();
this.target[this.key] = this.start;
};
module.exports = LoadValues;

View file

@ -7,12 +7,19 @@ var PlayNext = function ()
if (tweenData.next)
{
console.log('next');
this.setCurrentTweenData(tweenData.next);
}
else if (this.loop)
{
console.log('loop', this.loopDelay);
// leaves the state in PENDING_RENDER
this.setCurrentTweenData(this.data[0]);
this.target[this.key] = this.currentTweenData.startValue;
if (this.loopDelay > 0)
{
this.countdown = this.loopDelay;
@ -21,11 +28,15 @@ var PlayNext = function ()
}
else if (this.completeDelay > 0)
{
console.log('completeDelay');
this.countdown = this.completeDelay;
this.state = TWEEN_CONST.COMPLETE_DELAY;
}
else
{
console.log('complete');
this.state = TWEEN_CONST.PENDING_REMOVE;
}
};

View file

@ -14,7 +14,6 @@ var SetStateFromEnd = function (tween, tweenData)
}
else if (tweenData.repeatCounter > 0)
{
// No hold or yoyo, but we do have a repeat
tweenData.repeatCounter--;
// Reset the elapsed
@ -46,7 +45,6 @@ var SetStateFromStart = function (tween, tweenData)
{
if (tweenData.repeatCounter > 0)
{
// No hold or yoyo, but we do have a repeat
tweenData.repeatCounter--;
// Reset the elapsed