Skip to content

Commit 08b8d68

Browse files
committed
Lots of Tween updates, fleshing out concepts and ideas.
1 parent 418af73 commit 08b8d68

4 files changed

Lines changed: 158 additions & 20 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: 'a21447a0-34c1-11e7-a7cc-235ca839179c'
2+
build: '52ed8ac0-3529-11e7-a5a4-694da76b1298'
33
};
44
module.exports = CHECKSUM;

v3/src/tween/Tween.js

Lines changed: 146 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var GetValue = require('../utils/object/GetValue');
22
var GetEaseFunction = require('./GetEaseFunction');
33
var CloneObject = require('../utils/object/Clone');
4-
var TweenData = require('./TweenData');
4+
var MergeRight = require('../utils/object/MergeRight');
5+
// var TweenData = require('./TweenData');
56

67
var RESERVED = [ 'targets', 'ease', 'duration', 'yoyo', 'repeat', 'loop', 'paused', 'useFrames', 'offset' ];
78

@@ -58,6 +59,14 @@ var RESERVED = [ 'targets', 'ease', 'duration', 'yoyo', 'repeat', 'loop', 'pause
5859
y: { value: 300, duration: 1000, ease: 'Sine' }
5960
});
6061
62+
var tween = this.tweens.add({
63+
targets: player,
64+
props: {
65+
x: { value: 400, duration: 2000, ease: 'Power1' },
66+
y: { value: 300, duration: 1000, ease: 'Sine' }
67+
}
68+
});
69+
6170
*/
6271

6372
var Tween = function (manager, config)
@@ -97,6 +106,16 @@ var Tween = function (manager, config)
97106
this.loop = true;
98107
}
99108

109+
// Move to global
110+
this.defaultInstance = {
111+
key: '',
112+
running: false,
113+
complete: false,
114+
current: 0,
115+
queue: [],
116+
totalDuration: 0
117+
};
118+
100119
this.defaultTweenData = {
101120
value: undefined,
102121
progress: 0,
@@ -107,13 +126,21 @@ var Tween = function (manager, config)
107126
repeat: this.repeat,
108127
loop: this.loop,
109128
delay: this.delay,
110-
startAt: undefined
129+
startAt: undefined,
130+
elapsed: 0
111131
};
112132

113133
this.paused = GetValue(config, 'paused', false);
114134

115135
this.useFrames = GetValue(config, 'useFrames', false);
116136

137+
this.autoStart = GetValue(config, 'autoStart', true);
138+
139+
this.running = this.autoStart;
140+
141+
this.progress = 0;
142+
this.totalDuration = 0;
143+
117144
this.onStart;
118145
this.onStartScope;
119146
this.onStartParams;
@@ -158,29 +185,131 @@ Tween.prototype = {
158185
{
159186
// For now let's just assume `config.props` is being used:
160187

161-
// this.defaultTweenData = {
162-
// value: undefined,
163-
// progress: 0,
164-
// startTime: 0,
165-
// ease: this.ease,
166-
// duration: this.duration,
167-
// yoyo: this.yoyo,
168-
// repeat: this.repeat,
169-
// loop: this.loop,
170-
// delay: this.delay,
171-
// startAt: undefined
172-
// };
188+
// props: {
189+
// x: 400,
190+
// y: 300
191+
// }
192+
193+
// props: {
194+
// x: { value: 400, duration: 2000, ease: 'Power1' },
195+
// y: { value: 300, duration: 1000, ease: 'Sine' }
196+
// }
173197

174198
for (var key in config.props)
175199
{
176-
var data = CloneObject(this.defaultTweenData);
177-
178-
this.props[key] =
200+
// Check it's not a string or number (or function?)
201+
// TODO: value might be an Array
202+
203+
var data;
204+
var value = config.props[key];
205+
206+
if (typeof value === 'number')
207+
{
208+
data = CloneObject(this.defaultTweenData);
209+
210+
data.value = value;
211+
}
212+
else if (typeof value === 'string')
213+
{
214+
// Do something :)
215+
}
216+
else
217+
{
218+
data = MergeRight(this.defaultTweenData, config.props[key]);
219+
}
220+
221+
// this.props = [
222+
// {
223+
// key: 'x',
224+
// running: true,
225+
// complete: false,
226+
// current: 0,
227+
// queue: [ TweenData, TweenData, TweenData ],
228+
// totalDuration: Number (ms)
229+
// }
230+
// ]
231+
232+
// Convert to ms
233+
data.duration *= 1000;
234+
235+
var propertyMarker = CloneObject(this.defaultInstance);
236+
237+
propertyMarker.key = key;
238+
239+
// Adapt these to support array based multi-inserts
240+
propertyMarker.queue.push(data);
241+
propertyMarker.totalDuration = data.duration;
242+
243+
this.props.push(propertyMarker);
244+
245+
this.totalDuration += propertyMarker.totalDuration;
179246
}
180247
},
181248

182249
update: function (timestep, delta)
183250
{
251+
if (!this.running)
252+
{
253+
return;
254+
}
255+
256+
// Calculate tweens
257+
258+
var list = this.props;
259+
var targets = this.targets;
260+
261+
// this.props = [
262+
// {
263+
// key: 'x',
264+
// start: [ Target0 startValue, Target1 startValue, Target2 startValue ],
265+
// running: true,
266+
// complete: false,
267+
// current: 0,
268+
// queue: [ TweenData, TweenData, TweenData ],
269+
// totalDuration: Number (ms)
270+
// }
271+
// ]
272+
273+
for (var i = 0; i < list.length; i++)
274+
{
275+
var entry = list[i];
276+
277+
// Update TweenData
278+
279+
if (entry.running)
280+
{
281+
// TweenData = {
282+
// value: undefined,
283+
// progress: 0,
284+
// startTime: 0,
285+
// ease: this.ease,
286+
// duration: this.duration,
287+
// yoyo: this.yoyo,
288+
// repeat: this.repeat,
289+
// loop: this.loop,
290+
// delay: this.delay,
291+
// startAt: undefined,
292+
// elapsed: 0
293+
// };
294+
295+
var tweenData = entry.queue[entry.current];
296+
297+
tweenData.elapsed += delta;
298+
299+
if (tweenData.elapsed > tweenData.duration)
300+
{
301+
tweenData.elapsed = tweenData.duration;
302+
}
303+
304+
// What % is that?
305+
tweenData.progress = tweenData.elapsed / tweenData.duration;
306+
307+
for (var t = 0; t < targets.length; t++)
308+
{
309+
targets[i][entry.key] = tweenData.value;
310+
}
311+
}
312+
}
184313

185314
},
186315

v3/src/tween/TweenData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ TweenData.prototype = {
3131

3232
var TweenData = function (config)
3333
{
34-
this.property = ;
34+
this.property;
3535

3636
this.value;
3737

v3/src/tween/TweenManager.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
var GetValue = require('../utils/object/GetValue');
32
var EventDispatcher = require('../events/EventDispatcher');
43
var Tween = require('./Tween');
54

@@ -27,6 +26,11 @@ TweenManager.prototype = {
2726

2827
add: function (config)
2928
{
29+
var tween = new Tween(this, config);
30+
31+
this.list.push(tween);
32+
33+
return tween;
3034
},
3135

3236
// Add a 'to' GSAP equivalent?
@@ -41,7 +45,12 @@ TweenManager.prototype = {
4145

4246
update: function (timestamp, delta)
4347
{
48+
var list = this.list;
4449

50+
for (var i = 0; i < list.length; i++)
51+
{
52+
list[i].update(timestamp, delta);
53+
}
4554
},
4655

4756
globalTimeScale: function ()

0 commit comments

Comments
 (0)