1+ var Clamp = require ( '../../math/Clamp' ) ;
12var Class = require ( '../../utils/Class' ) ;
23var DegToRad = require ( '../../math/DegToRad' ) ;
34
@@ -23,18 +24,32 @@ var Particle = new Class({
2324 this . scaleX = 1 ;
2425 this . scaleY = 1 ;
2526
27+ this . angle = 0 ;
28+
29+ this . alpha = 1 ;
30+
31+ // rads
2632 this . rotation = 0 ;
2733
2834 this . scrollFactorX = 1 ;
2935 this . scrollFactorY = 1 ;
3036
31- this . color = 0xFFFFFFFF ;
37+ this . color = 0xffffffff ;
38+
39+ // in ms
40+ this . life = 1000 ;
41+ this . lifeCurrent = 1000 ;
3242
33- // Floats?
34- this . life = 1 ;
35- this . lifeStep = 1 ;
36- this . normLifeStep = 1 ;
43+ // ease data
44+ this . data = {
45+ tint : { min : 0xffffff , max : 0xffffff , current : 0xffffff } ,
46+ alpha : { min : 1 , max : 1 } ,
47+ angle : { min : 0 , max : 0 } ,
48+ scaleX : { min : 1 , max : 1 } ,
49+ scaleY : { min : 1 , max : 1 }
50+ } ;
3751
52+ /*
3853 this.start = {
3954 tint: 0xFFFFFF,
4055 alpha: 1,
@@ -48,6 +63,7 @@ var Particle = new Class({
4863 scale: { x: 1, y: 1 },
4964 angle: 0
5065 };
66+ */
5167 } ,
5268
5369 reset : function ( x , y , frame )
@@ -62,17 +78,21 @@ var Particle = new Class({
6278 this . velocityX = 0 ;
6379 this . velocityY = 0 ;
6480
65- this . scaleX = 1 ;
66- this . scaleY = 1 ;
81+ this . life = 1000 ;
82+ this . lifeCurrent = 1000 ;
6783
68- this . rotation = 0 ;
84+ // this.scaleX = 1;
85+ // this.scaleY = 1;
86+
87+ // this.rotation = 0;
6988
70- this . color = 0xFFFFFFFF ;
89+ // this.color = 0xFFFFFFFF;
7190
72- this . life = 1 ;
73- this . lifeStep = 1 ;
74- this . normLifeStep = 1 ;
91+ // this.life = 1;
92+ // this.lifeStep = 1;
93+ // this.normLifeStep = 1;
7594
95+ /*
7696 var start = this.start;
7797
7898 start.tint = 0xFFFFFF;
@@ -88,13 +108,14 @@ var Particle = new Class({
88108 end.scale.x = 1;
89109 end.scale.y = 1;
90110 end.angle = 0;
111+ */
91112
92113 return this ;
93114 } ,
94115
95116 isAlive : function ( )
96117 {
97- return ( this . lifeStep > 0 ) ;
118+ return ( this . lifeCurrent > 0 ) ;
98119 } ,
99120
100121 // var rad = DegToRad(Between(this.minEmitAngle, this.maxEmitAngle));
@@ -117,26 +138,63 @@ var Particle = new Class({
117138 // particle.color = (particle.color & 0x00FFFFFF) | (((this.startAlpha * 0xFF)|0) << 24);
118139 // particle.index = this.alive.length;
119140
141+ // this.data = {
142+ // tint: { min: 0xffffff, max: 0xffffff, current: 0xffffff },
143+ // alpha: { min: 1, max: 1, current: 1 },
144+ // angle: { min: 0, max: 0, current: 0 },
145+ // scaleX: { min: 1, max: 1, current: 1 },
146+ // scaleY: { min: 1, max: 1, current: 1 }
147+ // };
148+
120149 emit : function ( emitter )
121150 {
151+ // var rad = DegToRad(emitter.angle.getRandom());
152+
153+ // this.velocityX = Math.cos(rad) * emitter.velocity.getRandomX();
154+ // this.velocityY = Math.sin(rad) * emitter.velocity.getRandomY();
155+
156+ this . velocityX = emitter . velocity . getRandomX ( ) ;
157+ this . velocityY = emitter . velocity . getRandomY ( ) ;
158+
122159 var rad = DegToRad ( emitter . angle . getRandom ( ) ) ;
123160
124- this . velocityX = Math . cos ( rad ) * emitter . velocity . getRandomX ( ) ;
125- this . velocityY = Math . sin ( rad ) * emitter . velocity . getRandomY ( ) ;
161+ if ( rad !== 0 )
162+ {
163+ this . velocityX *= Math . cos ( rad ) ;
164+ this . velocityY *= Math . sin ( rad ) ;
165+ }
126166
127- this . life = Math . max ( this . life , Number . MIN_VALUE ) ;
128- this . lifeStep = this . life ;
167+ this . life = emitter . lifespan . getRandom ( ) ;
168+ this . lifeCurrent = this . life ;
129169
130- emitter . scale . copyX ( this . start . scale ) ;
131- emitter . scale . copyY ( this . end . scale ) ;
170+ // eased values
132171
133- this . start . alpha = emitter . alpha . min ;
134- this . end . alpha = emitter . alpha . max ;
172+ // emitter.scale.copyXToMinMax(this.data.scaleX) ;
173+ // emitter.scale.copyYToMinMax(this.data.scaleY) ;
135174
136- this . start . rotation = emitter . particleAngle . min ;
137- this . end . rotation = emitter . particleAngle . max ;
175+ // emitter.particleAngle.copyToMinMax(this.data.angle);
138176
139- this . color = ( this . color & 0x00ffffff ) | ( ( ( this . start . alpha * 0xff ) | 0 ) << 24 ) ;
177+ // emitter.alpha.copyToMinMax(this.data.alpha);
178+
179+
180+
181+ // this.scaleX = emitter.scale.xMin;
182+ // this.scaleY = emitter.scale.yMin;
183+
184+ // this.rotation = DegToRad(emitter.particleAngle.min);
185+
186+ // Set the starting ease data
187+
188+ // emitter.scale.copyX(this.start.scale);
189+ // emitter.scale.copyY(this.end.scale);
190+
191+ // this.start.alpha = emitter.alpha.min;
192+ // this.end.alpha = emitter.alpha.max;
193+
194+ // this.start.rotation = emitter.particleAngle.min;
195+ // this.end.rotation = emitter.particleAngle.max;
196+
197+ // this.color = (this.color & 0x00ffffff) | (((this.start.alpha * 0xff) | 0) << 24);
140198
141199 this . index = emitter . alive . length ;
142200 } ,
@@ -159,19 +217,27 @@ var Particle = new Class({
159217 // particle.color = (particle.color & 0x00FFFFFF) | (((alphaf * 0xFF)|0) << 24);
160218 // particle.rotation = rotation;
161219
162- update : function ( emitter , step )
220+ // delta = ms, step = delta / 1000
221+ update : function ( emitter , delta , step )
163222 {
164- this . normLifeStep = 1 - this . lifeStep / this . life ;
223+ // How far along in life is this particle? (t = 0 to 1)
224+ // var t = this.lifeCurrent / this.life, 0, 1;
165225
166226 this . velocityX += ( emitter . gravity . x * step ) ;
167227 this . velocityY += ( emitter . gravity . y * step ) ;
168228
169229 this . x += this . velocityX * step ;
170230 this . y += this . velocityY * step ;
171231
172- this . lifeStep -= step ;
232+ // scale
233+
234+ // rotation
235+
236+ // alpha
237+
238+ this . lifeCurrent -= delta ;
173239
174- return ( this . lifeStep <= 0 ) ;
240+ return ( this . lifeCurrent <= 0 ) ;
175241 }
176242
177243} ) ;
0 commit comments