Skip to content

Commit 609ea7e

Browse files
committed
Added ability to Scale particles when emitted.
1 parent 4f950ae commit 609ea7e

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

examples/particles.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ function create() {
3333

3434
game.stage.backgroundColor = 0x337799;
3535

36-
p = game.add.emitter(200, 100, 50);
36+
p = game.add.emitter(200, 100, 250);
3737

3838
// p.width = 200;
3939
// p.height = 200;
4040

4141
// keys, frames, quantity, collide
4242
// p.makeParticles(['diamond', 'carrot', 'star']);
43-
p.makeParticles('balls', [0,1,2,3,4,5]);
44-
// p.makeParticles('pixies', [0,1,2,3]);
43+
// p.makeParticles('balls', [0,1,2,3,4,5]);
44+
p.makeParticles('pixies', [0,1,2,3]);
45+
46+
p.minParticleScale = 0.1;
47+
p.maxParticleScale = 0.5;
4548

4649
// Steady constant stream at 250ms delay and 10 seconds lifespan
4750
// p.start(false, 10000, 250, 100);

src/particles/arcade/Emitter.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,25 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
4646
*/
4747
this.maxParticleSpeed = new Phaser.Point(100, 100);
4848

49+
/**
50+
* The minimum possible scale of a particle.
51+
* The default value is 1.
52+
*/
53+
this.minParticleScale = 1;
54+
55+
/**
56+
* The maximum possible scale of a particle.
57+
* The default value is 1.
58+
*/
59+
this.maxParticleScale = 1;
60+
4961
/**
5062
* The minimum possible angular velocity of a particle. The default value is -360.
51-
* NOTE: rotating particles are more expensive to draw than non-rotating ones!
5263
*/
5364
this.minRotation = -360;
5465

5566
/**
5667
* The maximum possible angular velocity of a particle. The default value is 360.
57-
* NOTE: rotating particles are more expensive to draw than non-rotating ones!
5868
*/
5969
this.maxRotation = 360;
6070

@@ -325,7 +335,6 @@ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
325335

326336
if (this.width > 1 || this.height > 1)
327337
{
328-
// particle.reset(this.x - this.game.rnd.integerInRange(this.left, this.right), this.y - this.game.rnd.integerInRange(this.top, this.bottom));
329338
particle.reset(this.x - this.game.rnd.integerInRange(this.left, this.right), this.y - this.game.rnd.integerInRange(this.top, this.bottom));
330339
}
331340
else
@@ -366,6 +375,12 @@ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
366375
particle.body.angularVelocity = this.minRotation;
367376
}
368377

378+
if (this.minParticleScale !== 1 || this.maxParticleScale !== 1)
379+
{
380+
var scale = this.game.rnd.realInRange(this.minParticleScale, this.maxParticleScale);
381+
particle.scale.setTo(scale, scale);
382+
}
383+
369384
particle.body.drag.x = this.particleDrag.x;
370385
particle.body.drag.y = this.particleDrag.y;
371386

0 commit comments

Comments
 (0)