Skip to content

Commit 1c9e23f

Browse files
committed
Emitter.start has a new parameter: forceQuantity which will force the quantity of a flow of particles to be the given value (request phaserjs#853)
Emitter.explode is a new short-cut for exploding a fixed quantity of particles at once. Emitter.flow is a new short-cut for creating a flow of particles based on the given frequency.
1 parent 1225294 commit 1c9e23f

3 files changed

Lines changed: 45 additions & 10 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Version 2.0.6 - "Jornhill" - -in development-
6363
* Stage no longer creates the Phaser.Canvas object, but Game itself does in the setupRenderer method.
6464
* Canvas.create has deprecated the noCocoon parameter as it's no longer required. The parameter is still in the signature, but no longer used in the method.
6565
* Time.add allows you to add an existing Phaser.Timer to the timer pool (request #864)
66+
* Emitter.start has a new parameter: forceQuantity which will force the quantity of a flow of particles to be the given value (request #853)
6667

6768
### CocoonJS Specific Updates
6869

@@ -88,6 +89,8 @@ Version 2.0.6 - "Jornhill" - -in development-
8889
* Loader.pack will allow you to load in a new Phaser Asset Pack JSON file. An Asset Pack is a specially structured file that allows you to define all assets for your game in an external file. The file can be split into sections, allowing you to control loading a specific set of files from it. An example JSON file can be found in the `resources\Asset Pack JSON Format` folder and examples of use in the Phaser Examples repository.
8990
* Loader.totalQueuedPacks returns the number of Asset Packs in the queue.
9091
* Loader.totalLoadedPacks returns the number of Asset Packs already loaded.
92+
* Emitter.explode is a new short-cut for exploding a fixed quantity of particles at once.
93+
* Emitter.flow is a new short-cut for creating a flow of particles based on the given frequency.
9194

9295

9396
### Bug Fixes

build/phaser.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,8 @@ declare module Phaser {
29312931

29322932
at(object: any): void;
29332933
emitParticle(): void;
2934+
explode(lifespan?: number, quantity?: number): void;
2935+
flow(lifespan?: number, frequency?: number, quantity?: number): void;
29342936
kill(): void;
29352937
makeParticles(keys: any, frames?: any, quantity?: number, collide?: boolean, collideWorldBounds?: boolean): Phaser.Particles.Arcade.Emitter;
29362938
reset(x: number, y: number, health?: number): Phaser.Particles;
@@ -2940,7 +2942,7 @@ declare module Phaser {
29402942
setSize(width: number, height: number): void;
29412943
setXSpeed(min: number, max: number): void;
29422944
setYSpeed(min: number, max: number): void;
2943-
start(explode?: boolean, lifespan?: number, frequency?: number, quantity?: number): void;
2945+
start(explode?: boolean, lifespan?: number, frequency?: number, quantity?: number, forceQuantity?: boolean): void;
29442946
update(): void;
29452947
revive(): void;
29462948

src/particles/arcade/Emitter.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
*/
66

77
/**
8-
* Phaser - ArcadeEmitter
9-
*
108
* @class Phaser.Particles.Arcade.Emitter
11-
* @classdesc Emitter is a lightweight particle emitter. It can be used for one-time explosions or for
12-
* continuous effects like rain and fire. All it really does is launch Particle objects out
13-
* at set intervals, and fixes their positions and velocities accorindgly.
9+
*
10+
* @classdesc Emitter is a lightweight particle emitter that uses Arcade Physics.
11+
* It can be used for one-time explosions or for continuous effects like rain and fire.
12+
* All it really does is launch Particle objects out at set intervals, and fixes their positions and velocities accorindgly.
13+
*
1414
* @constructor
1515
* @extends Phaser.Group
1616
* @param {Phaser.Game} game - Current game instance.
1717
* @param {number} [x=0] - The x coordinate within the Emitter that the particles are emitted from.
1818
* @param {number} [y=0] - The y coordinate within the Emitter that the particles are emitted from.
19-
* @param {number} [maxParticles=50] - The total number of particles in this emitter..
19+
* @param {number} [maxParticles=50] - The total number of particles in this emitter.
2020
*/
2121

2222
Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
2323

2424
/**
25-
* @property {number} maxParticles - The total number of particles in this emitter..
25+
* @property {number} maxParticles - The total number of particles in this emitter.
2626
* @default
2727
*/
2828
this.maxParticles = maxParticles || 50;
@@ -398,20 +398,50 @@ Phaser.Particles.Arcade.Emitter.prototype.revive = function () {
398398

399399
};
400400

401+
/**
402+
* Call this function to emit the given quantity of particles at all once (an explosion)
403+
*
404+
* @method Phaser.Particles.Arcade.Emitter#explode
405+
* @param {number} [lifespan=0] - How long each particle lives once emitted in ms. 0 = forever.
406+
* @param {number} [quantity=0] - How many particles to launch.
407+
*/
408+
Phaser.Particles.Arcade.Emitter.prototype.explode = function (lifespan, quantity) {
409+
410+
this.start(true, lifespan, 0, quantity, false);
411+
412+
};
413+
414+
/**
415+
* Call this function to start emitting a flow of particles at the given frequency.
416+
*
417+
* @method Phaser.Particles.Arcade.Emitter#flow
418+
* @param {number} [lifespan=0] - How long each particle lives once emitted in ms. 0 = forever.
419+
* @param {number} [frequency=250] - Frequency is how often to emit a particle, given in ms.
420+
* @param {number} [quantity=0] - How many particles to launch.
421+
*/
422+
Phaser.Particles.Arcade.Emitter.prototype.flow = function (lifespan, frequency, quantity) {
423+
424+
this.start(false, lifespan, frequency, quantity, true);
425+
426+
};
427+
401428
/**
402429
* Call this function to start emitting particles.
430+
*
403431
* @method Phaser.Particles.Arcade.Emitter#start
404432
* @param {boolean} [explode=true] - Whether the particles should all burst out at once (true) or at the frequency given (false).
405433
* @param {number} [lifespan=0] - How long each particle lives once emitted in ms. 0 = forever.
406434
* @param {number} [frequency=250] - Ignored if Explode is set to true. Frequency is how often to emit 1 particle. Value given in ms.
407435
* @param {number} [quantity=0] - How many particles to launch. 0 = "all of the particles".
436+
* @param {number} [forceQuantity=false] - If true and creating a particle flow, the quantity emitted will be forced to the be quantity given in this call.
408437
*/
409-
Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity) {
438+
Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity, forceQuantity) {
410439

411440
if (typeof explode === 'undefined') { explode = true; }
412441
if (typeof lifespan === 'undefined') { lifespan = 0; }
413442
if (typeof frequency === 'undefined' || frequency === null) { frequency = 250; }
414443
if (typeof quantity === 'undefined') { quantity = 0; }
444+
if (typeof forceQuantity === 'undefined') { forceQuantity = false; }
415445

416446
this.revive();
417447

@@ -422,7 +452,7 @@ Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, f
422452
this.lifespan = lifespan;
423453
this.frequency = frequency;
424454

425-
if (explode)
455+
if (explode || forceQuantity)
426456
{
427457
this._quantity = quantity;
428458
}

0 commit comments

Comments
 (0)