Removed Tween.startDelay because you can do it via TweenData.delay. Added new Duration calculation functions and TD caches.

This commit is contained in:
photonstorm 2017-05-25 14:33:31 +01:00
parent 9470eedf10
commit 1c268871e0
9 changed files with 28 additions and 45 deletions

View file

@ -15,7 +15,6 @@ module.exports = [
'repeat',
'repeatDelay',
'startAt',
'startDelay',
'targets',
'useFrames',
'yoyo'

View file

@ -16,12 +16,8 @@ var Tween = function (manager, data)
// If true then duration, delay, etc values are all frame totals
this.useFrames = false;
// Time in ms/frames before the tween starts for the very first time
// never used again once the tween has begun, even if it loops.
this.startDelay = 0;
// Infinitely loop this tween?
// When enabled it will play through ALL TweenDatas again (doesn't apply to just a single TD)
// When enabled it will play through ALL TweenDatas again (use repeat to loop a single TD)
this.loop = false;
// Time in ms/frames before the tween loops again if loop is true
@ -30,7 +26,7 @@ var Tween = function (manager, data)
// Time in ms/frames before the 'onComplete' event fires. This never fires if loop = true (as it never completes)
this.completeDelay = 0;
// Countdown timer (used by startDelay, loopDelay and completeDelay)
// Countdown timer (used by loopDelay and completeDelay)
this.countdown = 0;
this.state = TWEEN_CONST.PENDING_ADD;

View file

@ -250,7 +250,6 @@ var TweenBuilder = function (manager, config)
tween.loop = GetBoolean(config, 'loop', false);
tween.loopDelay = GetAdvancedValue(config, 'loopDelay', 0);
tween.completeDelay = GetAdvancedValue(config, 'completeDelay', 0);
tween.startDelay = GetAdvancedValue(config, 'startDelay', 0);
tween.paused = GetBoolean(config, 'paused', false);
return tween;

View file

@ -47,7 +47,7 @@ var TweenData = function (target, key, value, ease, delay, duration, yoyo, hold,
// How many repeats are left to run?
repeatCounter: 0,
// Value Data:
// Ease Value Data:
start: 0,
current: 0,
@ -55,6 +55,10 @@ var TweenData = function (target, key, value, ease, delay, duration, yoyo, hold,
startCache: 0,
endCache: 0,
// Time Durations
t1: 0,
t2: 0,
// LoadValue generation functions
gen: {
delay: delay,

View file

@ -4,41 +4,36 @@ var CalcDuration = function ()
var data = this.data;
// Duration is derived from:
// TweenData.duration
// TweenData.delay
// TweenData.hold
// x TweenData.repeat
for (var i = 0; i < this.totalData; i++)
{
var tweenData = data[i];
var total = tweenData.delay;
var single = tweenData.duration;
// Set t1 (duration + hold + yoyo)
tweenData.t1 = tweenData.duration + tweenData.hold;
if (tweenData.yoyo)
{
single *= 2;
tweenData.t1 += tweenData.duration;
}
single += tweenData.hold;
// Set t2 (repeatDelay + duration + hold + yoyo)
tweenData.t2 = tweenData.t1 + tweenData.repeatDelay;
var totalRepeats = (tweenData.repeat === -1) ? 999999999999 : tweenData.repeat;
// Total Duration
tweenData.totalDuration = tweenData.delay + tweenData.t1;
single += single * totalRepeats;
tweenData.totalDuration += tweenData.t2 * (tweenData.repeat === -1) ? 999999999999 : tweenData.repeat;
single += tweenData.repeatDelay * totalRepeats;
total += single;
if (total > max)
if (tweenData.totalDuration > max)
{
max = total;
max = tweenData.totalDuration;
}
}
// this.loop = false;
// this.loopDelay = 0;
// this.completeDelay = 0;
return max;
};

View file

@ -19,7 +19,7 @@ var Init = function ()
tweenData.repeatDelay = gen.repeatDelay(i, totalTargets, target);
}
this.totalDuration = this.calcDuration();
this.calcDuration();
console.log('Tween totalDuration', this.totalDuration);

View file

@ -18,15 +18,7 @@ var Play = function ()
// Reset the TweenData
this.resetTweenData();
if (this.startDelay > 0)
{
this.countdown = this.startDelay;
this.state = TWEEN_CONST.START_DELAY;
}
else
{
this.state = TWEEN_CONST.ACTIVE;
}
this.state = TWEEN_CONST.ACTIVE;
}
};

View file

@ -31,7 +31,6 @@ var Update = function (timestamp, delta)
break;
case TWEEN_CONST.LOOP_DELAY:
case TWEEN_CONST.START_DELAY:
this.countdown -= delta;

View file

@ -16,12 +16,11 @@ var TWEEN_CONST = {
PENDING_ADD: 20,
PAUSED: 21,
START_DELAY: 22,
LOOP_DELAY: 23,
ACTIVE: 24,
COMPLETE_DELAY: 25,
PENDING_REMOVE: 26,
REMOVED: 27
LOOP_DELAY: 22,
ACTIVE: 23,
COMPLETE_DELAY: 24,
PENDING_REMOVE: 25,
REMOVED: 26
};