Skip to content

Commit f84980c

Browse files
committed
Lots of Tween updates and fixes for loop and yoyo handling.
1 parent 198fc35 commit f84980c

8 files changed

Lines changed: 52 additions & 33 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '5c937cc0-3b0e-11e7-abb1-9b5937a3e478'
2+
build: '43c65050-3b1d-11e7-88f6-353b3d1c591c'
33
};
44
module.exports = CHECKSUM;

v3/src/tween/Tween.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ var Tween = function (manager, target, key)
2727
// if true then duration, delay, etc values are all frame totals
2828
this.useFrames = false;
2929

30+
// infinitely loop this tween?
31+
this.loop = false;
32+
3033
// Time in ms/frames before the 'onComplete' event fires
3134
this.onCompleteDelay = 0;
3235

@@ -36,7 +39,7 @@ var Tween = function (manager, target, key)
3639
// 0 = Waiting to be added to the TweenManager
3740
// 1 = Paused (dev needs to invoke Tween.start)
3841
// 2 = Started, but waiting for delay to expire
39-
// 3 = Playing Forward
42+
// 3 = Playing Forwards
4043
// 4 = Playing Backwards
4144
// 5 = Completed
4245
this.state = 0;

v3/src/tween/TweenBuilder.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ var TweenBuilder = function (manager, config)
161161
// Get Tween value + op
162162
var key = props[p].key;
163163
var values = props[p].value;
164+
var prev = null;
164165

165166
if (!Array.isArray(values))
166167
{
@@ -176,6 +177,7 @@ var TweenBuilder = function (manager, config)
176177
// Set Tween properties (TODO: Callbacks)
177178

178179
tween.completeDelay = GetAdvancedValue(value, 'completeDelay', defaultCompleteDelay);
180+
tween.loop = GetValue(value, 'loop', defaultLoop);
179181

180182
// Build the TweenData
181183
for (var i = 0; i < values.length; i++)
@@ -190,17 +192,20 @@ var TweenBuilder = function (manager, config)
190192
var yoyo = GetValue(value, 'yoyo', defaultYoyo);
191193
var repeat = GetAdvancedValue(value, 'repeat', defaultRepeat);
192194
var repeatDelay = GetAdvancedValue(value, 'repeatDelay', defaultRepeatDelay);
193-
var loop = GetValue(value, 'loop', defaultLoop);
194195
var delay = GetAdvancedValue(value, 'delay', defaultDelay);
195196

196-
if (repeat === -1)
197+
var tweenData = TweenData(valueOp, ease, duration, yoyo, repeat, delay, repeatDelay);
198+
199+
tweenData.prev = prev;
200+
201+
if (prev)
197202
{
198-
loop = true;
203+
prev.next = tweenData;
199204
}
200205

201-
var tweenData = TweenData(valueOp, ease, duration, yoyo, repeat, loop, delay, repeatDelay);
202-
203206
tween.data.push(tweenData);
207+
208+
prev = tweenData;
204209
}
205210

206211
tween.current = tween.data[0];

v3/src/tween/TweenData.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var TweenData = function (value, ease, duration, yoyo, repeat, loop, delay, repeatDelay)
1+
var TweenData = function (value, ease, duration, yoyo, repeat, delay, repeatDelay)
22
{
33
return {
44

5-
// A function to call when starting the tween, to populate the 'start' and 'end' values with
5+
// A function to call when starting the tween, populates the 'start' and 'end' values
66
value: value,
77

88
// the ease function this tween uses
@@ -11,22 +11,19 @@ var TweenData = function (value, ease, duration, yoyo, repeat, loop, delay, repe
1111
// duration of the tween in ms/frames, excludes time for yoyo or repeats
1212
duration: duration,
1313

14-
// alternate the tween back to its start position again?
14+
// return the tween back to its start position again?
1515
yoyo: yoyo,
1616

17-
// number of times to repeat the tween (-1 = forever, same as setting loop=true)
17+
// number of times to repeat the tween
1818
repeat: repeat,
1919

20-
// infinitely loop this tween?
21-
loop: loop,
22-
23-
// time in ms/frames between tween will start its first run
20+
// time in ms/frames before tween will start
2421
delay: delay,
2522

2623
// time in ms/frames before repeat will start
2724
repeatDelay: repeatDelay,
2825

29-
// between 0 and 1 showing completion of current portion of tween
26+
// between 0 and 1 showing completion of this TweenData
3027
progress: 0,
3128

3229
// delta counter
@@ -38,9 +35,9 @@ var TweenData = function (value, ease, duration, yoyo, repeat, loop, delay, repe
3835
// how many repeats are left to run?
3936
repeatCounter: 0,
4037

41-
// 0 = Waiting to be added to the TweenManager
42-
// 1 = Paused (dev needs to invoke Tween.start)
43-
// 2 = Started, but waiting for delay to expire
38+
// 0 = Waiting for Start
39+
// 1 = Waiting for countdown to expire
40+
// 2 = Started, waiting for next render to Load Values
4441
// 3 = Playing Forward
4542
// 4 = Playing Backwards
4643
// 5 = Completed

v3/src/tween/components/SetCurrentTweenData.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
var SetCurrentTweenData = function (index)
1+
var SetCurrentTweenData = function (tween)
22
{
3-
var tween = this.data[index];
3+
tween.progress = 0;
4+
tween.elapsed = 0;
45

5-
tween.repeatCounter = (tween.loop) ? Number.MAX_SAFE_INTEGER : tween.repeat;
6+
tween.repeatCounter = (tween.repeat === -1) ? Number.MAX_SAFE_INTEGER : tween.repeat;
67

78
if (tween.delay > 0)
89
{
910
tween.countdown = tween.delay;
10-
tween.state = 2;
11+
tween.state = 1;
1112
}
1213
else
1314
{
14-
tween.state = 3;
15+
tween.state = 2;
1516
}
1617

1718
this.tween = tween;

v3/src/tween/components/Start.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ var Start = function ()
55
return;
66
}
77

8-
this.setCurrentTweenData(0);
9-
10-
this.loadValues();
8+
this.setCurrentTweenData(this.data[0]);
119
};
1210

1311
module.exports = Start;

v3/src/tween/components/Update.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ var Update = function (timestamp, delta)
55
if (UpdateTweenData(this, this.tween, timestamp, delta))
66
{
77
// Next TweenData
8-
9-
10-
// Tween has completed
11-
this.state = 5;
8+
if (this.tween.next)
9+
{
10+
this.setCurrentTweenData(this.tween.next);
11+
}
12+
else if (this.loop)
13+
{
14+
this.setCurrentTweenData(this.data[0]);
15+
}
16+
else
17+
{
18+
// Tween has completed
19+
this.state = 5;
20+
}
1221
}
1322

1423
return (this.state === 5);

v3/src/tween/components/UpdateTweenData.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,23 @@ var ProcessRepeat = function (parent, tween)
104104

105105
var UpdateTweenData = function (parent, tween, timestep, delta)
106106
{
107-
if (tween.state === 2)
107+
if (tween.state === 1)
108108
{
109109
// Waiting for delay to expire
110110
tween.countdown -= (parent.useFrames) ? 1 : delta;
111111

112112
if (tween.countdown <= 0)
113113
{
114-
tween.state = 3;
114+
tween.state = 2;
115115
}
116116
}
117117

118+
if (tween.state === 2)
119+
{
120+
parent.loadValues();
121+
tween.state = 3;
122+
}
123+
118124
if (tween.state === 3)
119125
{
120126
// Playing forwards

0 commit comments

Comments
 (0)