Added Tween.loopCounter, Tween.loop is now an integer. Tween.progress, Tween.duration, Tween.totalProgress and Tween.totalDuration all calculated.

This commit is contained in:
photonstorm 2017-05-25 14:51:00 +01:00
parent 1c268871e0
commit 3b98cc5966
7 changed files with 47 additions and 13 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '35aaa140-4047-11e7-a72a-f5daee9806ea'
build: '1713cee0-4151-11e7-9b92-99548f7e932e'
};
module.exports = CHECKSUM;

View file

@ -16,26 +16,46 @@ var Tween = function (manager, data)
// If true then duration, delay, etc values are all frame totals
this.useFrames = false;
// Infinitely loop this tween?
// When enabled it will play through ALL TweenDatas again (use repeat to loop a single TD)
this.loop = false;
// Loop this tween? Can be -1 for an infinite loop, or an integer.
// When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD)
this.loop = 0;
// Time in ms/frames before the tween loops again if loop is true
// Time in ms/frames before the tween loops.
this.loopDelay = 0;
// How many loops are left to run?
this.loopCounter = 0;
// 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 loopDelay and completeDelay)
this.countdown = 0;
// The current state of the tween
this.state = TWEEN_CONST.PENDING_ADD;
// Does the Tween start off paused? (if so it needs to be started with Tween.play)
this.paused = false;
this.totalDuration = 0;
// Elapsed time in ms/frames of this run through the Tween.
this.elapsed = 0;
// Total elapsed time in ms/frames of the entire Tween, including looping.
this.totalElapsed = 0;
// Time in ms/frames for the whole Tween to play through once, excluding loop amounts and loop delays
this.duration = 0;
// Value between 0 and 1. The amount through the Tween, excluding loops.
this.progress = 0;
// Time in ms/frames for the Tween to complete (including looping)
this.totalDuration = 0;
// Value between 0 and 1. The amount through the entire Tween, including looping.
this.totalProgress = 0;
this.callbacks = {
onStart: { callback: null, scope: null, params: null },
onUpdate: { callback: null, scope: null, params: null },

View file

@ -247,7 +247,7 @@ var TweenBuilder = function (manager, config)
tween.totalTargets = targets.length;
tween.useFrames = GetBoolean(config, 'useFrames', false);
tween.loop = GetBoolean(config, 'loop', false);
tween.loop = GetBoolean(config, 'loop', 0);
tween.loopDelay = GetAdvancedValue(config, 'loopDelay', 0);
tween.completeDelay = GetAdvancedValue(config, 'completeDelay', 0);
tween.paused = GetBoolean(config, 'paused', false);

View file

@ -30,11 +30,12 @@ var CalcDuration = function ()
}
}
// this.loop = false;
// this.loopDelay = 0;
// this.completeDelay = 0;
// Excludes loop values
this.duration = max;
return max;
this.loopCounter = (this.loop === -1) ? 999999999999 : this.loop;
this.totalDuration = ((this.duration + this.loopDelay) * this.loopCounter) + this.completeDelay;
};
module.exports = CalcDuration;

View file

@ -21,7 +21,10 @@ var Init = function ()
this.calcDuration();
console.log('Tween totalDuration', this.totalDuration);
this.progress = 0;
this.totalProgress = 0;
console.log('Tween duration', this.duration, 'totalDuration', this.totalDuration);
if (this.paused)
{

View file

@ -2,10 +2,14 @@ var TWEEN_CONST = require('../const');
var NextState = function ()
{
if (this.loop)
if (this.loopCounter > 0)
{
this.resetTweenData(true);
this.elapsed = 0;
this.progress = 0;
this.loopCounter--;
if (this.loopDelay > 0)
{
this.countdown = this.loopDelay;

View file

@ -8,6 +8,12 @@ var Update = function (timestamp, delta)
delta = 1;
}
this.elapsed += delta;
this.progress = this.elapsed / this.duration;
this.totalElapsed += delta;
this.totalProgress = this.totalElapsed / this.totalDuration;
switch (this.state)
{
case TWEEN_CONST.ACTIVE: