11var Class = require ( '../../utils/Class' ) ;
22var DegToRad = require ( '../../math/DegToRad' ) ;
3- var FloatBetween = require ( '../../math/FloatBetween' ) ;
43
54var Particle = new Class ( {
65
@@ -44,10 +43,10 @@ var Particle = new Class({
4443 // ease data
4544 this . data = {
4645 tint : { min : 0xffffff , max : 0xffffff , current : 0xffffff } ,
47- alpha : { min : 1 , max : 1 , calc : 0 } ,
48- angle : { min : 0 , max : 0 , calc : 0 } ,
49- scaleX : { min : 1 , max : 1 , calc : 0 } ,
50- scaleY : { min : 1 , max : 1 , calc : 0 }
46+ alpha : { min : 1 , max : 1 } ,
47+ angle : { min : 0 , max : 0 } ,
48+ scaleX : { min : 1 , max : 1 } ,
49+ scaleY : { min : 1 , max : 1 }
5150 } ;
5251 } ,
5352
@@ -67,15 +66,15 @@ var Particle = new Class({
6766 emitter . zone . getRandomPoint ( this ) ;
6867 }
6968
70- this . x += emitter . x . getNext ( ) ;
71- this . y += emitter . y . getNext ( ) ;
69+ this . x += emitter . x . onEmit ( this , 'x' ) ;
70+ this . y += emitter . y . onEmit ( this , 'y' ) ;
7271
73- var sx = emitter . speedX . getNext ( ) ;
74- var sy = emitter . speedY . getNext ( ) ;
72+ var sx = emitter . speedX . onEmit ( this , 'speedX' ) ;
73+ var sy = ( emitter . speedY ) ? emitter . speedY . onEmit ( this , 'speedY' ) : sx ;
7574
7675 if ( emitter . radial )
7776 {
78- var rad = DegToRad ( emitter . emitterAngle . getNext ( ) ) ;
77+ var rad = DegToRad ( emitter . emitterAngle . onEmit ( this , 'angle' ) ) ;
7978
8079 this . velocityX = Math . cos ( rad ) * Math . abs ( sx ) ;
8180 this . velocityY = Math . sin ( rad ) * Math . abs ( sy ) ;
@@ -86,104 +85,17 @@ var Particle = new Class({
8685 this . velocityY = sy ;
8786 }
8887
89- this . life = emitter . lifespan . getNext ( ) ;
88+ this . life = emitter . lifespan . onEmit ( this , 'lifespan' ) ;
9089 this . lifeCurrent = this . life ;
9190
92- // eased values
91+ this . scaleX = emitter . scaleX . onEmit ( this , 'scaleX' ) ;
92+ this . scaleY = ( emitter . scaleY ) ? emitter . scaleY . onEmit ( this , 'scaleY' ) : this . scaleX ;
9393
94- var dataScaleX = this . data . scaleX ;
95- var dataScaleY = this . data . scaleY ;
96- var dataAngle = this . data . angle ;
97- var dataAlpha = this . data . alpha ;
98-
99- emitter . scaleX . copyToMinMax ( dataScaleX ) ;
100- emitter . scaleY . copyToMinMax ( dataScaleY ) ;
101- emitter . particleAngle . copyToMinMax ( dataAngle ) ;
102- emitter . alpha . copyToMinMax ( dataAlpha ) ;
103-
104- // Random overrides
105-
106- if ( emitter . randomScaleX )
107- {
108- var randomScaleX = FloatBetween ( emitter . randomScaleX [ 0 ] , emitter . randomScaleX [ 1 ] ) ;
109-
110- // If there is no current ease value set we override them both
111- if ( dataScaleX . min === dataScaleX . max )
112- {
113- dataScaleX . min = randomScaleX ;
114- dataScaleX . max = randomScaleX ;
115- }
116- else
117- {
118- // Otherwise we just reset the start value, so it still eases to the end value
119- dataScaleX . min = randomScaleX ;
120- }
121- }
122-
123- if ( emitter . randomScaleY )
124- {
125- var randomScaleY = FloatBetween ( emitter . randomScaleY [ 0 ] , emitter . randomScaleY [ 1 ] ) ;
126-
127- // If there is no current ease value set we override them both
128- if ( dataScaleY . min === dataScaleY . max )
129- {
130- dataScaleY . min = randomScaleY ;
131- dataScaleY . max = randomScaleY ;
132- }
133- else
134- {
135- // Otherwise we just reset the start value, so it still eases to the end value
136- dataScaleY . min = randomScaleY ;
137- }
138- }
139-
140- if ( emitter . randomAngle )
141- {
142- var randomAngle = FloatBetween ( emitter . randomAngle [ 0 ] , emitter . randomAngle [ 1 ] ) ;
143-
144- // If there is no current ease value set we override them both
145- if ( dataAngle . min === dataAngle . max )
146- {
147- dataAngle . min = randomAngle ;
148- dataAngle . max = randomAngle ;
149- }
150- else
151- {
152- // Otherwise we just reset the start value, so it still eases to the end value
153- dataAngle . min = randomAngle ;
154- }
155- }
156-
157- if ( emitter . randomAlpha )
158- {
159- var randomAlpha = FloatBetween ( emitter . randomAlpha [ 0 ] , emitter . randomAlpha [ 1 ] ) ;
160-
161- // If there is no current ease value set we override them both
162- if ( dataAlpha . min === dataAlpha . max )
163- {
164- dataAlpha . min = randomAlpha ;
165- dataAlpha . max = randomAlpha ;
166- }
167- else
168- {
169- // Otherwise we just reset the start value, so it still eases to the end value
170- dataAlpha . min = randomAlpha ;
171- }
172- }
173-
174- // Pre-calc ease values
175- dataScaleX . calc = dataScaleX . max - dataScaleX . min ;
176- dataScaleY . calc = dataScaleY . max - dataScaleY . min ;
177- dataAngle . calc = dataAngle . max - dataAngle . min ;
178- dataAlpha . calc = dataAlpha . max - dataAlpha . min ;
94+ this . angle = emitter . particleAngle . onEmit ( this , 'angle' ) ;
95+ this . rotation = DegToRad ( this . angle ) ;
17996
180- // Set initial values
181- this . scaleX = dataScaleX . min ;
182- this . scaleY = dataScaleY . min ;
183- this . angle = dataAngle . min ;
184- this . rotation = DegToRad ( dataAngle . min ) ;
97+ this . alpha = emitter . alpha . onEmit ( this , 'alpha' ) ;
18598
186- this . alpha = dataAlpha . min ;
18799 this . color = ( this . color & 0x00FFFFFF ) | ( ( ( this . alpha * 0xFF ) | 0 ) << 24 ) ;
188100
189101 this . index = emitter . alive . length ;
@@ -197,21 +109,27 @@ var Particle = new Class({
197109 // How far along in life is this particle? (t = 0 to 1)
198110 var t = 1 - ( this . lifeCurrent / this . life ) ;
199111
200- this . velocityX += ( emitter . gravity . x * step ) ;
201- this . velocityY += ( emitter . gravity . y * step ) ;
112+ this . velocityX += ( emitter . gravityX * step ) ;
113+ this . velocityY += ( emitter . gravityY * step ) ;
202114
203115 this . x += this . velocityX * step ;
204116 this . y += this . velocityY * step ;
205117
206- var data = this . data ;
118+ this . scaleX = emitter . scaleX . onUpdate ( this , 'scaleX' , t , this . scaleX ) ;
207119
208- this . scaleX = data . scaleX . calc * emitter . easingFunctionScale ( t ) + data . scaleX . min ;
209- this . scaleY = data . scaleY . calc * emitter . easingFunctionScale ( t ) + data . scaleY . min ;
120+ if ( emitter . scaleY )
121+ {
122+ this . scaleY = emitter . scaleY . onUpdate ( this , 'scaleY' , t , this . scaleY ) ;
123+ }
124+ else
125+ {
126+ this . scaleY = this . scaleX ;
127+ }
210128
211- this . angle = data . angle . calc * emitter . easingFunctionRotation ( t ) + data . angle . min ;
129+ this . angle = emitter . particleAngle . onUpdate ( this , 'angle' , t , this . angle ) ;
212130 this . rotation = DegToRad ( this . angle ) ;
213131
214- this . alpha = data . alpha . calc * emitter . easingFunctionAlpha ( t ) + data . alpha . min ;
132+ this . alpha = emitter . alpha . onUpdate ( this , 'alpha' , t , this . alpha ) ;
215133
216134 this . color = ( this . color & 0x00FFFFFF ) | ( ( ( this . alpha * 0xFF ) | 0 ) << 24 ) ;
217135
0 commit comments