diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 25059c849..f2a717970 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '35aaa140-4047-11e7-a72a-f5daee9806ea' +build: '1713cee0-4151-11e7-9b92-99548f7e932e' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/tween/Tween.js b/v3/src/tween/Tween.js index ad88ec642..a2dd40a41 100644 --- a/v3/src/tween/Tween.js +++ b/v3/src/tween/Tween.js @@ -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 }, diff --git a/v3/src/tween/TweenBuilder.js b/v3/src/tween/TweenBuilder.js index b9b7fb5d5..316d802c5 100644 --- a/v3/src/tween/TweenBuilder.js +++ b/v3/src/tween/TweenBuilder.js @@ -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); diff --git a/v3/src/tween/components/CalcDuration.js b/v3/src/tween/components/CalcDuration.js index a48c2c41c..c9e5e3782 100644 --- a/v3/src/tween/components/CalcDuration.js +++ b/v3/src/tween/components/CalcDuration.js @@ -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; diff --git a/v3/src/tween/components/Init.js b/v3/src/tween/components/Init.js index 9e4d1ea94..893a2482c 100644 --- a/v3/src/tween/components/Init.js +++ b/v3/src/tween/components/Init.js @@ -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) { diff --git a/v3/src/tween/components/NextState.js b/v3/src/tween/components/NextState.js index 10e5df6d9..1349c416c 100644 --- a/v3/src/tween/components/NextState.js +++ b/v3/src/tween/components/NextState.js @@ -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; diff --git a/v3/src/tween/components/Update.js b/v3/src/tween/components/Update.js index 2f0fab942..727a42bf2 100644 --- a/v3/src/tween/components/Update.js +++ b/v3/src/tween/components/Update.js @@ -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: