Lots of Tween updates and fixes for loop and yoyo handling.

This commit is contained in:
Richard Davey 2017-05-17 17:28:01 +01:00
parent 198fc359f7
commit f84980ce54
8 changed files with 52 additions and 33 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '5c937cc0-3b0e-11e7-abb1-9b5937a3e478'
build: '43c65050-3b1d-11e7-88f6-353b3d1c591c'
};
module.exports = CHECKSUM;

View file

@ -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;

View file

@ -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];

View file

@ -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

View file

@ -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;

View file

@ -5,9 +5,7 @@ var Start = function ()
return;
}
this.setCurrentTweenData(0);
this.loadValues();
this.setCurrentTweenData(this.data[0]);
};
module.exports = Start;

View file

@ -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);

View file

@ -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