Skip to content

Commit 2ed87f5

Browse files
committed
Safety nets on property accessors.
1 parent afc73e4 commit 2ed87f5

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

v3/src/gameobjects/particles/EmitterOp.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,9 @@ var EmitterOp = new Class({
207207
{
208208
var value = FloatBetween(this.start, this.end);
209209

210-
var data = particle.data[key];
211-
212-
if (data)
210+
if (particle && particle.data[key])
213211
{
214-
data.min = value;
212+
particle.data[key].min = value;
215213
}
216214

217215
return value;
@@ -228,10 +226,13 @@ var EmitterOp = new Class({
228226

229227
easedValueEmit: function (particle, key)
230228
{
231-
var data = particle.data[key];
229+
if (particle)
230+
{
231+
var data = particle.data[key];
232232

233-
data.min = this.start;
234-
data.max = this.end;
233+
data.min = this.start;
234+
data.max = this.end;
235+
}
235236

236237
return this.start;
237238
},

v3/src/gameobjects/particles/Particle.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var Particle = new Class({
4444
this.data = {
4545
tint: { min: 0xffffff, max: 0xffffff, current: 0xffffff },
4646
alpha: { min: 1, max: 1 },
47-
angle: { min: 0, max: 0 },
47+
rotate: { min: 0, max: 0 },
4848
scaleX: { min: 1, max: 1 },
4949
scaleY: { min: 1, max: 1 }
5050
};
@@ -100,7 +100,7 @@ var Particle = new Class({
100100

101101
if (emitter.radial)
102102
{
103-
var rad = DegToRad(emitter.emitterAngle.onEmit(this, 'angle'));
103+
var rad = DegToRad(emitter.angle.onEmit(this, 'angle'));
104104

105105
this.velocityX = Math.cos(rad) * Math.abs(sx);
106106
this.velocityY = Math.sin(rad) * Math.abs(sy);
@@ -117,7 +117,7 @@ var Particle = new Class({
117117
this.scaleX = emitter.scaleX.onEmit(this, 'scaleX');
118118
this.scaleY = (emitter.scaleY) ? emitter.scaleY.onEmit(this, 'scaleY') : this.scaleX;
119119

120-
this.angle = emitter.particleAngle.onEmit(this, 'angle');
120+
this.angle = emitter.rotate.onEmit(this, 'rotate');
121121
this.rotation = DegToRad(this.angle);
122122

123123
this.alpha = emitter.alpha.onEmit(this, 'alpha');
@@ -152,7 +152,7 @@ var Particle = new Class({
152152
this.scaleY = this.scaleX;
153153
}
154154

155-
this.angle = emitter.particleAngle.onUpdate(this, 'angle', t, this.angle);
155+
this.angle = emitter.rotate.onUpdate(this, 'rotate', t, this.angle);
156156
this.rotation = DegToRad(this.angle);
157157

158158
this.alpha = emitter.alpha.onUpdate(this, 'alpha', t, this.alpha);

v3/src/gameobjects/particles/ParticleEmitter.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var ParticleEmitter = new Class({
3838
this.x = new EmitterOp(config, 'x', 0);
3939
this.y = new EmitterOp(config, 'y', 0);
4040

41-
// A radial emitter will emit particles in all directions between emitterAngle min and max, using speed as the value
41+
// A radial emitter will emit particles in all directions between angle min and max, using speed as the value
4242
// A point emitter will emit particles only in the direction derived from the speedX and speedY values
4343
this.radial = GetFastValue(config, 'radial', true);
4444

@@ -77,9 +77,9 @@ var ParticleEmitter = new Class({
7777

7878
this.lifespan = new EmitterOp(config, 'lifespan', 1000);
7979

80-
this.emitterAngle = new EmitterOp(config, 'angle', { min: 0, max: 360 });
80+
this.angle = new EmitterOp(config, 'angle', { min: 0, max: 360 });
8181

82-
this.particleAngle = new EmitterOp(config, 'particleAngle', 0);
82+
this.rotate = new EmitterOp(config, 'rotate', 0);
8383

8484
// Callbacks
8585

@@ -97,11 +97,11 @@ var ParticleEmitter = new Class({
9797
this.deathCallbackScope = callbackScope;
9898
}
9999

100-
// Set to hard limit the amount of particle objects this emitter is allowed to create
100+
// Set to hard limit the amount of particle objects this emitter is allowed to create. 0 means unlimited.
101101
this.maxParticles = GetFastValue(config, 'maxParticles', 0);
102102

103103
// How many particles are emitted each time the emitter updates
104-
this.quantity = GetFastValue(config, 'quantity', 1);
104+
this.quantity = new EmitterOp(config, 'quantity', 1);
105105

106106
// How often a particle is emitted in ms (if emitter is a constant / flow emitter)
107107
// If emitter is an explosion emitter this value will be -1.
@@ -297,7 +297,7 @@ var ParticleEmitter = new Class({
297297

298298
setEmitterAngle: function (value)
299299
{
300-
this.emitterAngle.onChange(value);
300+
this.angle.onChange(value);
301301

302302
return this;
303303
},
@@ -318,7 +318,7 @@ var ParticleEmitter = new Class({
318318

319319
setQuantity: function (quantity)
320320
{
321-
this.quantity = quantity;
321+
this.quantity.onChange(quantity);
322322

323323
return this;
324324
},
@@ -331,7 +331,7 @@ var ParticleEmitter = new Class({
331331

332332
if (quantity)
333333
{
334-
this.quantity = quantity;
334+
this.quantity.onChange(quantity);
335335
}
336336

337337
return this;
@@ -506,7 +506,7 @@ var ParticleEmitter = new Class({
506506

507507
this.frequency = frequency;
508508

509-
this.quantity = count;
509+
this.quantity.onChange(count);
510510

511511
return this.start();
512512
},
@@ -525,13 +525,16 @@ var ParticleEmitter = new Class({
525525

526526
emit: function (count, x, y)
527527
{
528-
if (count === undefined) { count = this.quantity; }
529-
530528
if (this.atLimit())
531529
{
532530
return;
533531
}
534532

533+
if (count === undefined)
534+
{
535+
count = this.quantity.onEmit();
536+
}
537+
535538
var dead = this.dead;
536539

537540
for (var i = 0; i < count; i++)

0 commit comments

Comments
 (0)