11var Class = require ( '../../utils/Class' ) ;
22var DegToRad = require ( '../../math/DegToRad' ) ;
3+ var DistanceBetween = require ( '../../math/distance/DistanceBetween' ) ;
34
45var Particle = new Class ( {
56
@@ -42,6 +43,7 @@ var Particle = new Class({
4243 this . scrollFactorX = 1 ;
4344 this . scrollFactorY = 1 ;
4445
46+ this . tint = 0xffffffff ;
4547 this . color = 0xffffffff ;
4648
4749 // in ms
@@ -107,6 +109,10 @@ var Particle = new Class({
107109 this . y += y ;
108110 }
109111
112+ this . life = emitter . lifespan . onEmit ( this , 'lifespan' ) ;
113+ this . lifeCurrent = this . life ;
114+ this . lifeT = 0 ;
115+
110116 var sx = emitter . speedX . onEmit ( this , 'speedX' ) ;
111117 var sy = ( emitter . speedY ) ? emitter . speedY . onEmit ( this , 'speedY' ) : sx ;
112118
@@ -117,6 +123,21 @@ var Particle = new Class({
117123 this . velocityX = Math . cos ( rad ) * Math . abs ( sx ) ;
118124 this . velocityY = Math . sin ( rad ) * Math . abs ( sy ) ;
119125 }
126+ else if ( emitter . moveTo )
127+ {
128+ var mx = emitter . moveToX . onEmit ( this , 'moveToX' ) ;
129+ var my = ( emitter . moveToY ) ? emitter . moveToY . onEmit ( this , 'moveToY' ) : mx ;
130+
131+ var angle = Math . atan2 ( my - this . y , mx - this . x ) ;
132+
133+ var speed = DistanceBetween ( this . x , this . y , mx , my ) / ( this . life / 1000 ) ;
134+
135+ // We know how many pixels we need to move, but how fast?
136+ // var speed = this.distanceToXY(displayObject, x, y) / (maxTime / 1000);
137+
138+ this . velocityX = Math . cos ( angle ) * speed ;
139+ this . velocityY = Math . sin ( angle ) * speed ;
140+ }
120141 else
121142 {
122143 this . velocityX = sx ;
@@ -134,10 +155,6 @@ var Particle = new Class({
134155
135156 this . delayCurrent = emitter . delay . onEmit ( this , 'delay' ) ;
136157
137- this . life = emitter . lifespan . onEmit ( this , 'lifespan' ) ;
138- this . lifeCurrent = this . life ;
139- this . lifeT = 0 ;
140-
141158 this . scaleX = emitter . scaleX . onEmit ( this , 'scaleX' ) ;
142159 this . scaleY = ( emitter . scaleY ) ? emitter . scaleY . onEmit ( this , 'scaleY' ) : this . scaleX ;
143160
@@ -148,7 +165,9 @@ var Particle = new Class({
148165
149166 this . alpha = emitter . alpha . onEmit ( this , 'alpha' ) ;
150167
151- this . color = ( this . color & 0x00FFFFFF ) | ( ( ( this . alpha * 0xFF ) | 0 ) << 24 ) ;
168+ this . tint = emitter . tint . onEmit ( this , 'tint' ) ;
169+
170+ this . color = ( this . tint & 0x00FFFFFF ) | ( ( ( this . alpha * 0xFF ) | 0 ) << 24 ) ;
152171
153172 this . index = emitter . alive . length ;
154173 } ,
@@ -276,7 +295,9 @@ var Particle = new Class({
276295
277296 this . alpha = emitter . alpha . onUpdate ( this , 'alpha' , t , this . alpha ) ;
278297
279- this . color = ( this . color & 0x00FFFFFF ) | ( ( ( this . alpha * 0xFF ) | 0 ) << 24 ) ;
298+ this . tint = emitter . tint . onUpdate ( this , 'tint' , t , this . tint ) ;
299+
300+ this . color = ( this . tint & 0x00FFFFFF ) | ( ( ( this . alpha * 0xFF ) | 0 ) << 24 ) ;
280301
281302 this . lifeCurrent -= delta ;
282303
0 commit comments