11var Class = require ( '../../utils/Class' ) ;
22var GetBoolean = require ( '../../tween/builder/GetBoolean' ) ;
3- var GetValue = require ( '../../utils/object/getValue ' ) ;
3+ var GetValue = require ( '../../utils/object/GetValue ' ) ;
44var Sprite = require ( '../sprite/Sprite' ) ;
55var Vector2 = require ( '../../math/Vector2' ) ;
66
@@ -26,6 +26,26 @@ var PathFollower = new Class({
2626 this . pathTween ;
2727 } ,
2828
29+ setPath : function ( path , config )
30+ {
31+ var tween = this . pathTween ;
32+
33+ if ( tween && tween . isPlaying ( ) )
34+ {
35+ tween . stop ( ) ;
36+ }
37+
38+ this . path = path ;
39+
40+ if ( config )
41+ {
42+ this . start ( config ) ;
43+ }
44+
45+ return this ;
46+ } ,
47+
48+ // rotation offset in radians
2949 setRotateToPath : function ( value , offset )
3050 {
3151 if ( offset === undefined ) { offset = 0 ; }
@@ -36,13 +56,22 @@ var PathFollower = new Class({
3656 return this ;
3757 } ,
3858
59+ isFollowing : function ( )
60+ {
61+ var tween = this . pathTween ;
62+
63+ return ( tween && tween . isPlaying ( ) ) ;
64+ } ,
65+
3966 start : function ( config )
4067 {
4168 if ( config === undefined ) { config = { } ; }
4269
43- if ( this . pathTween && this . pathTween . isPlaying ( ) )
70+ var tween = this . pathTween ;
71+
72+ if ( tween && tween . isPlaying ( ) )
4473 {
45- return ;
74+ tween . stop ( ) ;
4675 }
4776
4877 if ( typeof config === 'number' )
@@ -70,57 +99,64 @@ var PathFollower = new Class({
7099 return this ;
71100 } ,
72101
73- stop : function ( )
102+ pause : function ( )
74103 {
75- if ( this . pathTween && this . pathTween . isPlaying ( ) )
104+ var tween = this . pathTween ;
105+
106+ if ( tween && tween . isPlaying ( ) )
76107 {
77- this . pathTween . stop ( ) ;
108+ tween . pause ( ) ;
78109 }
79110
80111 return this ;
81112 } ,
82113
83- /*
84- playing: {
114+ resume : function ( )
115+ {
116+ var tween = this . pathTween ;
85117
86- get: function ( )
118+ if ( tween && tween . isPaused ( ) )
87119 {
88- return this.pathData.playing;
89- },
120+ tween . resume ( ) ;
121+ }
122+
123+ return this ;
124+ } ,
125+
126+ stop : function ( )
127+ {
128+ var tween = this . pathTween ;
90129
91- set: function (value )
130+ if ( tween && tween . isPlaying ( ) )
92131 {
93- if (!value)
94- {
95- this.stop();
96- }
97- else
98- {
99- this.start();
100- }
132+ tween . stop ( ) ;
101133 }
102134
103- }
104- */
135+ return this ;
136+ } ,
105137
106138 preUpdate : function ( time , delta )
107139 {
108140 this . anims . update ( time , delta ) ;
109141
110- if ( this . pathTween && this . pathTween . isPlaying ( ) )
142+ var tween = this . pathTween ;
143+
144+ if ( tween && tween . isPlaying ( ) )
111145 {
112- this . path . getPoint ( this . pathTween . getValue ( ) , this . pathVector ) ;
146+ var pathVector = this . pathVector ;
147+
148+ this . path . getPoint ( tween . getValue ( ) , pathVector ) ;
113149
114- this . pathVector . add ( this . pathOffset ) ;
150+ pathVector . add ( this . pathOffset ) ;
115151
116152 var oldX = this . x ;
117153 var oldY = this . y ;
118154
119- this . setPosition ( this . pathVector . x , this . pathVector . y ) ;
155+ this . setPosition ( pathVector . x , pathVector . y ) ;
120156
121157 if ( this . rotateToPath )
122158 {
123- this . rotation = Math . atan2 ( this . y - oldY , this . x - oldX ) + this . pathRotationOffset ;
159+ this . rotation = Math . atan2 ( this . y - oldY , this . x - oldX ) ;
124160 }
125161 }
126162 }
0 commit comments