11var GetValue = require ( '../utils/object/GetValue' ) ;
22var 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
36109Tween . prototype . constructor = Tween ;
37110
38111Tween . 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
47151module . exports = Tween ;
0 commit comments