Skip to content

Commit 80374dd

Browse files
committed
Particles are now passed through optional extra processors
1 parent fcaf470 commit 80374dd

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

v3/src/gameobjects/particles/Particle.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ var Particle = new Class({
4848
this.life = 1000;
4949
this.lifeCurrent = 1000;
5050

51+
// 0-1
52+
this.lifeT = 0;
53+
5154
// ease data
5255
this.data = {
5356
tint: { min: 0xffffff, max: 0xffffff, current: 0xffffff },
@@ -72,7 +75,7 @@ var Particle = new Class({
7275
if (emitter.zone)
7376
{
7477
// Updates particle.x and particle.y during this call
75-
emitter.zone.getRandomPoint(this);
78+
emitter.zone.getPoint(this);
7679
}
7780

7881
if (x === undefined)
@@ -130,6 +133,7 @@ var Particle = new Class({
130133

131134
this.life = emitter.lifespan.onEmit(this, 'lifespan');
132135
this.lifeCurrent = this.life;
136+
this.lifeT = 0;
133137

134138
this.scaleX = emitter.scaleX.onEmit(this, 'scaleX');
135139
this.scaleY = (emitter.scaleY) ? emitter.scaleY.onEmit(this, 'scaleY') : this.scaleX;
@@ -146,7 +150,7 @@ var Particle = new Class({
146150
this.index = emitter.alive.length;
147151
},
148152

149-
computeVelocity: function (emitter, step)
153+
computeVelocity: function (emitter, delta, step, processors)
150154
{
151155
var vx = this.velocityX;
152156
var vy = this.velocityY;
@@ -190,6 +194,12 @@ var Particle = new Class({
190194

191195
this.velocityX = vx;
192196
this.velocityY = vy;
197+
198+
// Apply any additional processors
199+
for (var i = 0; i < processors.length; i++)
200+
{
201+
processors[i].update(this, delta, step);
202+
}
193203
},
194204

195205
checkBounds: function (emitter)
@@ -221,14 +231,16 @@ var Particle = new Class({
221231
},
222232

223233
// delta = ms, step = delta / 1000
224-
update: function (delta, step)
234+
update: function (delta, step, processors)
225235
{
226236
var emitter = this.emitter;
227237

228238
// How far along in life is this particle? (t = 0 to 1)
229239
var t = 1 - (this.lifeCurrent / this.life);
230240

231-
this.computeVelocity(emitter, step);
241+
this.lifeT = t;
242+
243+
this.computeVelocity(emitter, delta, step, processors);
232244

233245
this.x += this.velocityX * step;
234246
this.y += this.velocityY * step;

0 commit comments

Comments
 (0)