11var Class = require ( '../../utils/Class' ) ;
22var DegToRad = require ( '../../math/DegToRad' ) ;
3+ var FloatBetween = require ( '../../math/FloatBetween' ) ;
34
45var Particle = new Class ( {
56
@@ -21,10 +22,11 @@ var Particle = new Class({
2122 this . scaleX = 1 ;
2223 this . scaleY = 1 ;
2324
24- this . angle = 0 ;
25-
2625 this . alpha = 1 ;
2726
27+ // degs
28+ this . angle = 0 ;
29+
2830 // rads
2931 this . rotation = 0 ;
3032
@@ -69,7 +71,7 @@ var Particle = new Class({
6971
7072 if ( emitter . radial )
7173 {
72- var rad = DegToRad ( emitter . angle . getRandom ( ) ) ;
74+ var rad = DegToRad ( emitter . emitterAngle . getRandom ( ) ) ;
7375
7476 this . velocityX = Math . cos ( rad ) * Math . abs ( sx ) ;
7577 this . velocityY = Math . sin ( rad ) * Math . abs ( sy ) ;
@@ -84,23 +86,101 @@ var Particle = new Class({
8486 this . lifeCurrent = this . life ;
8587
8688 // eased values
87- emitter . scale . copyXToMinMax ( this . data . scaleX ) ;
88- emitter . scale . copyYToMinMax ( this . data . scaleY ) ;
89- emitter . particleAngle . copyToMinMax ( this . data . angle ) ;
90- emitter . alpha . copyToMinMax ( this . data . alpha ) ;
89+
90+ var dataScaleX = this . data . scaleX ;
91+ var dataScaleY = this . data . scaleY ;
92+ var dataAngle = this . data . angle ;
93+ var dataAlpha = this . data . alpha ;
94+
95+ emitter . scale . copyXToMinMax ( dataScaleX ) ;
96+ emitter . scale . copyYToMinMax ( dataScaleY ) ;
97+ emitter . angle . copyToMinMax ( dataAngle ) ;
98+ emitter . alpha . copyToMinMax ( dataAlpha ) ;
99+
100+ // Random overrides
101+
102+ if ( emitter . randomScaleX )
103+ {
104+ var randomScaleX = FloatBetween ( emitter . randomScaleX [ 0 ] , emitter . randomScaleX [ 1 ] ) ;
105+
106+ // If there is no current ease value set we override them both
107+ if ( dataScaleX . min === dataScaleX . max )
108+ {
109+ dataScaleX . min = randomScaleX ;
110+ dataScaleX . max = randomScaleX ;
111+ }
112+ else
113+ {
114+ // Otherwise we just reset the start value, so it still eases to the end value
115+ dataScaleX . min = randomScaleX ;
116+ }
117+ }
118+
119+ if ( emitter . randomScaleY )
120+ {
121+ var randomScaleY = FloatBetween ( emitter . randomScaleY [ 0 ] , emitter . randomScaleY [ 1 ] ) ;
122+
123+ // If there is no current ease value set we override them both
124+ if ( dataScaleY . min === dataScaleY . max )
125+ {
126+ dataScaleY . min = randomScaleY ;
127+ dataScaleY . max = randomScaleY ;
128+ }
129+ else
130+ {
131+ // Otherwise we just reset the start value, so it still eases to the end value
132+ dataScaleY . min = randomScaleY ;
133+ }
134+ }
135+
136+ if ( emitter . randomAngle )
137+ {
138+ var randomAngle = FloatBetween ( emitter . randomAngle [ 0 ] , emitter . randomAngle [ 1 ] ) ;
139+
140+ // If there is no current ease value set we override them both
141+ if ( dataAngle . min === dataAngle . max )
142+ {
143+ dataAngle . min = randomAngle ;
144+ dataAngle . max = randomAngle ;
145+ }
146+ else
147+ {
148+ // Otherwise we just reset the start value, so it still eases to the end value
149+ dataAngle . min = randomAngle ;
150+ }
151+ }
152+
153+ if ( emitter . randomAlpha )
154+ {
155+ var randomAlpha = FloatBetween ( emitter . randomAlpha [ 0 ] , emitter . randomAlpha [ 1 ] ) ;
156+
157+ // If there is no current ease value set we override them both
158+ if ( dataAlpha . min === dataAlpha . max )
159+ {
160+ dataAlpha . min = randomAlpha ;
161+ dataAlpha . max = randomAlpha ;
162+ }
163+ else
164+ {
165+ // Otherwise we just reset the start value, so it still eases to the end value
166+ dataAlpha . min = randomAlpha ;
167+ }
168+ }
91169
92170 // Pre-calc ease values
93- this . data . scaleX . calc = this . data . scaleX . max - this . data . scaleX . min ;
94- this . data . scaleY . calc = this . data . scaleY . max - this . data . scaleY . min ;
95- this . data . angle . calc = this . data . angle . max - this . data . angle . min ;
96- this . data . alpha . calc = this . data . alpha . max - this . data . alpha . min ;
171+ dataScaleX . calc = dataScaleX . max - dataScaleX . min ;
172+ dataScaleY . calc = dataScaleY . max - dataScaleY . min ;
173+ dataAngle . calc = dataAngle . max - dataAngle . min ;
174+ dataAlpha . calc = dataAlpha . max - dataAlpha . min ;
97175
98176 // Set initial values
99- this . rotation = DegToRad ( this . data . angle . min ) ;
100- this . alpha = this . data . alpha . min ;
177+ this . scaleX = dataScaleX . min ;
178+ this . scaleY = dataScaleY . min ;
179+ this . angle = dataAngle . min ;
180+ this . rotation = DegToRad ( dataAngle . min ) ;
181+
182+ this . alpha = dataAlpha . min ;
101183 this . color = ( this . color & 0x00FFFFFF ) | ( ( ( this . alpha * 0xFF ) | 0 ) << 24 ) ;
102- this . scaleX = this . data . scaleX . min ;
103- this . scaleY = this . data . scaleY . min ;
104184
105185 this . index = emitter . alive . length ;
106186 } ,
@@ -117,12 +197,15 @@ var Particle = new Class({
117197 this . x += this . velocityX * step ;
118198 this . y += this . velocityY * step ;
119199
120- this . scaleX = this . data . scaleX . calc * emitter . easingFunctionScale ( t ) + this . data . scaleX . min ;
121- this . scaleY = this . data . scaleY . calc * emitter . easingFunctionScale ( t ) + this . data . scaleY . min ;
200+ var data = this . data ;
201+
202+ this . scaleX = data . scaleX . calc * emitter . easingFunctionScale ( t ) + data . scaleX . min ;
203+ this . scaleY = data . scaleY . calc * emitter . easingFunctionScale ( t ) + data . scaleY . min ;
122204
123- this . rotation = DegToRad ( this . data . angle . calc * emitter . easingFunctionRotation ( t ) + this . data . angle . min ) ;
205+ this . angle = data . angle . calc * emitter . easingFunctionRotation ( t ) + data . angle . min ;
206+ this . rotation = DegToRad ( this . angle ) ;
124207
125- this . alpha = this . data . alpha . calc * emitter . easingFunctionAlpha ( t ) + this . data . alpha . min ;
208+ this . alpha = data . alpha . calc * emitter . easingFunctionAlpha ( t ) + data . alpha . min ;
126209
127210 this . color = ( this . color & 0x00FFFFFF ) | ( ( ( this . alpha * 0xFF ) | 0 ) << 24 ) ;
128211
0 commit comments