mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Lots of Tween updates and fixes for loop and yoyo handling.
This commit is contained in:
parent
198fc359f7
commit
f84980ce54
8 changed files with 52 additions and 33 deletions
|
@ -1,4 +1,4 @@
|
||||||
var CHECKSUM = {
|
var CHECKSUM = {
|
||||||
build: '5c937cc0-3b0e-11e7-abb1-9b5937a3e478'
|
build: '43c65050-3b1d-11e7-88f6-353b3d1c591c'
|
||||||
};
|
};
|
||||||
module.exports = CHECKSUM;
|
module.exports = CHECKSUM;
|
|
@ -27,6 +27,9 @@ var Tween = function (manager, target, key)
|
||||||
// if true then duration, delay, etc values are all frame totals
|
// if true then duration, delay, etc values are all frame totals
|
||||||
this.useFrames = false;
|
this.useFrames = false;
|
||||||
|
|
||||||
|
// infinitely loop this tween?
|
||||||
|
this.loop = false;
|
||||||
|
|
||||||
// Time in ms/frames before the 'onComplete' event fires
|
// Time in ms/frames before the 'onComplete' event fires
|
||||||
this.onCompleteDelay = 0;
|
this.onCompleteDelay = 0;
|
||||||
|
|
||||||
|
@ -36,7 +39,7 @@ var Tween = function (manager, target, key)
|
||||||
// 0 = Waiting to be added to the TweenManager
|
// 0 = Waiting to be added to the TweenManager
|
||||||
// 1 = Paused (dev needs to invoke Tween.start)
|
// 1 = Paused (dev needs to invoke Tween.start)
|
||||||
// 2 = Started, but waiting for delay to expire
|
// 2 = Started, but waiting for delay to expire
|
||||||
// 3 = Playing Forward
|
// 3 = Playing Forwards
|
||||||
// 4 = Playing Backwards
|
// 4 = Playing Backwards
|
||||||
// 5 = Completed
|
// 5 = Completed
|
||||||
this.state = 0;
|
this.state = 0;
|
||||||
|
|
|
@ -161,6 +161,7 @@ var TweenBuilder = function (manager, config)
|
||||||
// Get Tween value + op
|
// Get Tween value + op
|
||||||
var key = props[p].key;
|
var key = props[p].key;
|
||||||
var values = props[p].value;
|
var values = props[p].value;
|
||||||
|
var prev = null;
|
||||||
|
|
||||||
if (!Array.isArray(values))
|
if (!Array.isArray(values))
|
||||||
{
|
{
|
||||||
|
@ -176,6 +177,7 @@ var TweenBuilder = function (manager, config)
|
||||||
// Set Tween properties (TODO: Callbacks)
|
// Set Tween properties (TODO: Callbacks)
|
||||||
|
|
||||||
tween.completeDelay = GetAdvancedValue(value, 'completeDelay', defaultCompleteDelay);
|
tween.completeDelay = GetAdvancedValue(value, 'completeDelay', defaultCompleteDelay);
|
||||||
|
tween.loop = GetValue(value, 'loop', defaultLoop);
|
||||||
|
|
||||||
// Build the TweenData
|
// Build the TweenData
|
||||||
for (var i = 0; i < values.length; i++)
|
for (var i = 0; i < values.length; i++)
|
||||||
|
@ -190,17 +192,20 @@ var TweenBuilder = function (manager, config)
|
||||||
var yoyo = GetValue(value, 'yoyo', defaultYoyo);
|
var yoyo = GetValue(value, 'yoyo', defaultYoyo);
|
||||||
var repeat = GetAdvancedValue(value, 'repeat', defaultRepeat);
|
var repeat = GetAdvancedValue(value, 'repeat', defaultRepeat);
|
||||||
var repeatDelay = GetAdvancedValue(value, 'repeatDelay', defaultRepeatDelay);
|
var repeatDelay = GetAdvancedValue(value, 'repeatDelay', defaultRepeatDelay);
|
||||||
var loop = GetValue(value, 'loop', defaultLoop);
|
|
||||||
var delay = GetAdvancedValue(value, 'delay', defaultDelay);
|
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);
|
tween.data.push(tweenData);
|
||||||
|
|
||||||
|
prev = tweenData;
|
||||||
}
|
}
|
||||||
|
|
||||||
tween.current = tween.data[0];
|
tween.current = tween.data[0];
|
||||||
|
|
|
@ -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 {
|
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,
|
value: value,
|
||||||
|
|
||||||
// the ease function this tween uses
|
// 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 of the tween in ms/frames, excludes time for yoyo or repeats
|
||||||
duration: duration,
|
duration: duration,
|
||||||
|
|
||||||
// alternate the tween back to its start position again?
|
// return the tween back to its start position again?
|
||||||
yoyo: yoyo,
|
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,
|
repeat: repeat,
|
||||||
|
|
||||||
// infinitely loop this tween?
|
// time in ms/frames before tween will start
|
||||||
loop: loop,
|
|
||||||
|
|
||||||
// time in ms/frames between tween will start its first run
|
|
||||||
delay: delay,
|
delay: delay,
|
||||||
|
|
||||||
// time in ms/frames before repeat will start
|
// time in ms/frames before repeat will start
|
||||||
repeatDelay: repeatDelay,
|
repeatDelay: repeatDelay,
|
||||||
|
|
||||||
// between 0 and 1 showing completion of current portion of tween
|
// between 0 and 1 showing completion of this TweenData
|
||||||
progress: 0,
|
progress: 0,
|
||||||
|
|
||||||
// delta counter
|
// delta counter
|
||||||
|
@ -38,9 +35,9 @@ var TweenData = function (value, ease, duration, yoyo, repeat, loop, delay, repe
|
||||||
// how many repeats are left to run?
|
// how many repeats are left to run?
|
||||||
repeatCounter: 0,
|
repeatCounter: 0,
|
||||||
|
|
||||||
// 0 = Waiting to be added to the TweenManager
|
// 0 = Waiting for Start
|
||||||
// 1 = Paused (dev needs to invoke Tween.start)
|
// 1 = Waiting for countdown to expire
|
||||||
// 2 = Started, but waiting for delay to expire
|
// 2 = Started, waiting for next render to Load Values
|
||||||
// 3 = Playing Forward
|
// 3 = Playing Forward
|
||||||
// 4 = Playing Backwards
|
// 4 = Playing Backwards
|
||||||
// 5 = Completed
|
// 5 = Completed
|
||||||
|
|
|
@ -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)
|
if (tween.delay > 0)
|
||||||
{
|
{
|
||||||
tween.countdown = tween.delay;
|
tween.countdown = tween.delay;
|
||||||
tween.state = 2;
|
tween.state = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tween.state = 3;
|
tween.state = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tween = tween;
|
this.tween = tween;
|
||||||
|
|
|
@ -5,9 +5,7 @@ var Start = function ()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setCurrentTweenData(0);
|
this.setCurrentTweenData(this.data[0]);
|
||||||
|
|
||||||
this.loadValues();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Start;
|
module.exports = Start;
|
||||||
|
|
|
@ -5,10 +5,19 @@ var Update = function (timestamp, delta)
|
||||||
if (UpdateTweenData(this, this.tween, timestamp, delta))
|
if (UpdateTweenData(this, this.tween, timestamp, delta))
|
||||||
{
|
{
|
||||||
// Next TweenData
|
// Next TweenData
|
||||||
|
if (this.tween.next)
|
||||||
|
{
|
||||||
// Tween has completed
|
this.setCurrentTweenData(this.tween.next);
|
||||||
this.state = 5;
|
}
|
||||||
|
else if (this.loop)
|
||||||
|
{
|
||||||
|
this.setCurrentTweenData(this.data[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Tween has completed
|
||||||
|
this.state = 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (this.state === 5);
|
return (this.state === 5);
|
||||||
|
|
|
@ -104,17 +104,23 @@ var ProcessRepeat = function (parent, tween)
|
||||||
|
|
||||||
var UpdateTweenData = function (parent, tween, timestep, delta)
|
var UpdateTweenData = function (parent, tween, timestep, delta)
|
||||||
{
|
{
|
||||||
if (tween.state === 2)
|
if (tween.state === 1)
|
||||||
{
|
{
|
||||||
// Waiting for delay to expire
|
// Waiting for delay to expire
|
||||||
tween.countdown -= (parent.useFrames) ? 1 : delta;
|
tween.countdown -= (parent.useFrames) ? 1 : delta;
|
||||||
|
|
||||||
if (tween.countdown <= 0)
|
if (tween.countdown <= 0)
|
||||||
{
|
{
|
||||||
tween.state = 3;
|
tween.state = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tween.state === 2)
|
||||||
|
{
|
||||||
|
parent.loadValues();
|
||||||
|
tween.state = 3;
|
||||||
|
}
|
||||||
|
|
||||||
if (tween.state === 3)
|
if (tween.state === 3)
|
||||||
{
|
{
|
||||||
// Playing forwards
|
// Playing forwards
|
||||||
|
|
Loading…
Reference in a new issue