Skip to content

Commit 345a77a

Browse files
committed
Lots of comments and examples.
1 parent 422468e commit 345a77a

2 files changed

Lines changed: 129 additions & 8 deletions

File tree

v3/src/tween/Tween.js

Lines changed: 112 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,90 @@
11
var GetValue = require('../utils/object/GetValue');
22
var TweenData = require('./TweenData');
33

4-
var Tween = function (manager)
4+
var RESERVED = [ 'targets', 'ease', 'duration', 'yoyo', 'repeat', 'loop', 'paused', 'useFrames', 'offset' ];
5+
6+
/*
7+
The following are all the same
8+
9+
var tween = this.tweens.add({
10+
targets: player,
11+
x: 200,
12+
duration: 2000,
13+
ease: 'Power1',
14+
yoyo: true
15+
});
16+
17+
var tween = this.tweens.add({
18+
targets: player,
19+
props: {
20+
x: 200
21+
}
22+
duration: 2000,
23+
ease: 'Power1',
24+
yoyo: true
25+
});
26+
27+
var tween = this.tweens.add({
28+
targets: player,
29+
x: { value: 200, duration: 2000, ease: 'Power1', yoyo: true }
30+
});
31+
32+
var tween = this.tweens.add({
33+
targets: player,
34+
props: {
35+
x: { value: 200, duration: 2000, ease: 'Power1', yoyo: true }
36+
}
37+
});
38+
39+
// Chained property tweens:
40+
// Each tween uses the same duration and ease because they've been 'globally' defined, except the middle one,
41+
// which uses its own duration as it overrides the global one
42+
43+
var tween = this.tweens.add({
44+
targets: player,
45+
x: [ { value: 200 }, { value: 300, duration: 50 }, { value: 400 } ],
46+
duration: 2000,
47+
ease: 'Power1',
48+
yoyo: true
49+
});
50+
51+
// Multiple property tweens:
52+
53+
var tween = this.tweens.add({
54+
targets: player,
55+
x: { value: 400, duration: 2000, ease: 'Power1' },
56+
y: { value: 300, duration: 1000, ease: 'Sine' }
57+
});
58+
59+
*/
60+
61+
var Tween = function (manager, config)
562
{
663
this.manager = manager;
764

8-
this.targets;
65+
// The following config properties are reserved words, i.e. they map to Tween related functions
66+
// and properties. However if you've got a target that has a property that matches one of the
67+
// reserved words, i.e. Target.duration - that you want to tween, then pass it inside a property
68+
// called `vars`. If present it will use the contents of the `vars` object instead.
69+
70+
this.targets = this.setTargets(GetValue(config, 'targets', null));
71+
972
this.ease;
10-
this.yoyo;
11-
this.repeat;
12-
this.loop; // same as repeat -1 (if set, overrides repeat value)
13-
this.paused;
73+
74+
this.duration = GetValue(config, 'duration', 1000);
75+
76+
// Only applied if this Tween is part of a Timeline
77+
this.offset = GetValue(config, 'offset', 0);
78+
79+
this.yoyo = GetValue(config, 'yoyo', false);
80+
this.repeat = GetValue(config, 'repeat', 0);
81+
82+
// same as repeat -1 (if set, overrides repeat value)
83+
this.loop = GetValue(config, 'loop', undefined);
84+
85+
this.paused = GetValue(config, 'paused', false);
86+
87+
this.useFrames = GetValue(config, 'useFrames', false);
1488

1589
this.onStart;
1690
this.onStartScope;
@@ -30,18 +104,48 @@ var Tween = function (manager)
30104

31105
this.callbackScope;
32106

33-
this.useFrames = false;
34107
};
35108

36109
Tween.prototype.constructor = Tween;
37110

38111
Tween.prototype = {
39112

40-
timeScale: function ()
113+
// Move to own functions
114+
115+
setTargets: function (targets)
41116
{
117+
if (typeof targets === 'function')
118+
{
119+
targets = targets.call();
120+
}
121+
122+
if (!Array.isArray(targets))
123+
{
124+
targets = [ targets ];
125+
}
42126

127+
return targets;
43128
},
44129

130+
eventCallback: function (type, callback, params, scope)
131+
{
132+
var types = [ 'onStart', 'onUpdate', 'onRepeat', 'onComplete' ];
133+
134+
if (types.indexOf(type) !== -1)
135+
{
136+
this[type] = callback;
137+
this[type + 'Params'] = params;
138+
this[type + 'Scope'] = scope;
139+
}
140+
141+
return this;
142+
},
143+
144+
timeScale: function ()
145+
{
146+
147+
}
148+
45149
};
46150

47151
module.exports = Tween;

v3/src/tween/TweenData.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
var TweenData = function (parent)
22
{
33
this.tween = parent;
4+
5+
this.property;
6+
7+
this.value;
8+
9+
this.ease;
10+
this.duration;
11+
this.yoyo;
12+
this.repeat;
13+
this.delay;
14+
this.startAt;
15+
this.onCompleteDelay;
16+
this.elasticity;
17+
418
};
519

620
TweenData.prototype.constructor = TweenData;
721

822
TweenData.prototype = {
23+
24+
25+
926
};
1027

1128
module.exports = TweenData;

0 commit comments

Comments
 (0)