From f84980ce54173f559b5322bbd955075355eec911 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 17 May 2017 17:28:01 +0100 Subject: [PATCH] Lots of Tween updates and fixes for loop and yoyo handling. --- v3/src/checksum.js | 2 +- v3/src/tween/Tween.js | 5 ++++- v3/src/tween/TweenBuilder.js | 15 ++++++++----- v3/src/tween/TweenData.js | 21 ++++++++----------- .../tween/components/SetCurrentTweenData.js | 11 +++++----- v3/src/tween/components/Start.js | 4 +--- v3/src/tween/components/Update.js | 17 +++++++++++---- v3/src/tween/components/UpdateTweenData.js | 10 +++++++-- 8 files changed, 52 insertions(+), 33 deletions(-) diff --git a/v3/src/checksum.js b/v3/src/checksum.js index f62f5e9ec..071442932 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '5c937cc0-3b0e-11e7-abb1-9b5937a3e478' +build: '43c65050-3b1d-11e7-88f6-353b3d1c591c' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/tween/Tween.js b/v3/src/tween/Tween.js index 38cc2fbed..407675da7 100644 --- a/v3/src/tween/Tween.js +++ b/v3/src/tween/Tween.js @@ -27,6 +27,9 @@ var Tween = function (manager, target, key) // if true then duration, delay, etc values are all frame totals this.useFrames = false; + // infinitely loop this tween? + this.loop = false; + // Time in ms/frames before the 'onComplete' event fires this.onCompleteDelay = 0; @@ -36,7 +39,7 @@ var Tween = function (manager, target, key) // 0 = Waiting to be added to the TweenManager // 1 = Paused (dev needs to invoke Tween.start) // 2 = Started, but waiting for delay to expire - // 3 = Playing Forward + // 3 = Playing Forwards // 4 = Playing Backwards // 5 = Completed this.state = 0; diff --git a/v3/src/tween/TweenBuilder.js b/v3/src/tween/TweenBuilder.js index 6d7a4ad0f..182ebd096 100644 --- a/v3/src/tween/TweenBuilder.js +++ b/v3/src/tween/TweenBuilder.js @@ -161,6 +161,7 @@ var TweenBuilder = function (manager, config) // Get Tween value + op var key = props[p].key; var values = props[p].value; + var prev = null; if (!Array.isArray(values)) { @@ -176,6 +177,7 @@ var TweenBuilder = function (manager, config) // Set Tween properties (TODO: Callbacks) tween.completeDelay = GetAdvancedValue(value, 'completeDelay', defaultCompleteDelay); + tween.loop = GetValue(value, 'loop', defaultLoop); // Build the TweenData for (var i = 0; i < values.length; i++) @@ -190,17 +192,20 @@ var TweenBuilder = function (manager, config) var yoyo = GetValue(value, 'yoyo', defaultYoyo); var repeat = GetAdvancedValue(value, 'repeat', defaultRepeat); var repeatDelay = GetAdvancedValue(value, 'repeatDelay', defaultRepeatDelay); - var loop = GetValue(value, 'loop', defaultLoop); var delay = GetAdvancedValue(value, 'delay', defaultDelay); - if (repeat === -1) + var tweenData = TweenData(valueOp, ease, duration, yoyo, repeat, delay, repeatDelay); + + tweenData.prev = prev; + + if (prev) { - loop = true; + prev.next = tweenData; } - var tweenData = TweenData(valueOp, ease, duration, yoyo, repeat, loop, delay, repeatDelay); - tween.data.push(tweenData); + + prev = tweenData; } tween.current = tween.data[0]; diff --git a/v3/src/tween/TweenData.js b/v3/src/tween/TweenData.js index 3bb36a78d..a1c7d2f85 100644 --- a/v3/src/tween/TweenData.js +++ b/v3/src/tween/TweenData.js @@ -1,8 +1,8 @@ -var TweenData = function (value, ease, duration, yoyo, repeat, loop, delay, repeatDelay) +var TweenData = function (value, ease, duration, yoyo, repeat, delay, repeatDelay) { return { - // A function to call when starting the tween, to populate the 'start' and 'end' values with + // A function to call when starting the tween, populates the 'start' and 'end' values value: value, // the ease function this tween uses @@ -11,22 +11,19 @@ var TweenData = function (value, ease, duration, yoyo, repeat, loop, delay, repe // duration of the tween in ms/frames, excludes time for yoyo or repeats duration: duration, - // alternate the tween back to its start position again? + // return the tween back to its start position again? yoyo: yoyo, - // number of times to repeat the tween (-1 = forever, same as setting loop=true) + // number of times to repeat the tween repeat: repeat, - // infinitely loop this tween? - loop: loop, - - // time in ms/frames between tween will start its first run + // time in ms/frames before tween will start delay: delay, // time in ms/frames before repeat will start repeatDelay: repeatDelay, - // between 0 and 1 showing completion of current portion of tween + // between 0 and 1 showing completion of this TweenData progress: 0, // delta counter @@ -38,9 +35,9 @@ var TweenData = function (value, ease, duration, yoyo, repeat, loop, delay, repe // how many repeats are left to run? repeatCounter: 0, - // 0 = Waiting to be added to the TweenManager - // 1 = Paused (dev needs to invoke Tween.start) - // 2 = Started, but waiting for delay to expire + // 0 = Waiting for Start + // 1 = Waiting for countdown to expire + // 2 = Started, waiting for next render to Load Values // 3 = Playing Forward // 4 = Playing Backwards // 5 = Completed diff --git a/v3/src/tween/components/SetCurrentTweenData.js b/v3/src/tween/components/SetCurrentTweenData.js index 034bcc04a..a88d69894 100644 --- a/v3/src/tween/components/SetCurrentTweenData.js +++ b/v3/src/tween/components/SetCurrentTweenData.js @@ -1,17 +1,18 @@ -var SetCurrentTweenData = function (index) +var SetCurrentTweenData = function (tween) { - var tween = this.data[index]; + tween.progress = 0; + tween.elapsed = 0; - tween.repeatCounter = (tween.loop) ? Number.MAX_SAFE_INTEGER : tween.repeat; + tween.repeatCounter = (tween.repeat === -1) ? Number.MAX_SAFE_INTEGER : tween.repeat; if (tween.delay > 0) { tween.countdown = tween.delay; - tween.state = 2; + tween.state = 1; } else { - tween.state = 3; + tween.state = 2; } this.tween = tween; diff --git a/v3/src/tween/components/Start.js b/v3/src/tween/components/Start.js index 0fa18c2aa..4f0e7cc8e 100644 --- a/v3/src/tween/components/Start.js +++ b/v3/src/tween/components/Start.js @@ -5,9 +5,7 @@ var Start = function () return; } - this.setCurrentTweenData(0); - - this.loadValues(); + this.setCurrentTweenData(this.data[0]); }; module.exports = Start; diff --git a/v3/src/tween/components/Update.js b/v3/src/tween/components/Update.js index 4447550e0..153e4730f 100644 --- a/v3/src/tween/components/Update.js +++ b/v3/src/tween/components/Update.js @@ -5,10 +5,19 @@ var Update = function (timestamp, delta) if (UpdateTweenData(this, this.tween, timestamp, delta)) { // Next TweenData - - - // Tween has completed - this.state = 5; + if (this.tween.next) + { + this.setCurrentTweenData(this.tween.next); + } + else if (this.loop) + { + this.setCurrentTweenData(this.data[0]); + } + else + { + // Tween has completed + this.state = 5; + } } return (this.state === 5); diff --git a/v3/src/tween/components/UpdateTweenData.js b/v3/src/tween/components/UpdateTweenData.js index cbe32062b..3cee18266 100644 --- a/v3/src/tween/components/UpdateTweenData.js +++ b/v3/src/tween/components/UpdateTweenData.js @@ -104,17 +104,23 @@ var ProcessRepeat = function (parent, tween) var UpdateTweenData = function (parent, tween, timestep, delta) { - if (tween.state === 2) + if (tween.state === 1) { // Waiting for delay to expire tween.countdown -= (parent.useFrames) ? 1 : delta; if (tween.countdown <= 0) { - tween.state = 3; + tween.state = 2; } } + if (tween.state === 2) + { + parent.loadValues(); + tween.state = 3; + } + if (tween.state === 3) { // Playing forwards