Skip to content

Commit ec4c2d4

Browse files
author
samme
committed
Emitter methods return the Emitter instance
to better allow chaining: - at - explode - flow - kill - revive - setAlpha - setRotation - setScale - setSize - setXSpeed - setYSpeed - start
1 parent d7b6d4e commit ec4c2d4

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/particles/arcade/Emitter.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,25 +408,31 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
408408
* Call this function to turn off all the particles and the emitter.
409409
*
410410
* @method Phaser.Particles.Arcade.Emitter#kill
411+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
411412
*/
412413
Phaser.Particles.Arcade.Emitter.prototype.kill = function () {
413414

414415
this.on = false;
415416
this.alive = false;
416417
this.exists = false;
417418

419+
return this;
420+
418421
};
419422

420423
/**
421424
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
422425
*
423426
* @method Phaser.Particles.Arcade.Emitter#revive
427+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
424428
*/
425429
Phaser.Particles.Arcade.Emitter.prototype.revive = function () {
426430

427431
this.alive = true;
428432
this.exists = true;
429433

434+
return this;
435+
430436
};
431437

432438
/**
@@ -435,13 +441,16 @@ Phaser.Particles.Arcade.Emitter.prototype.revive = function () {
435441
* @method Phaser.Particles.Arcade.Emitter#explode
436442
* @param {number} [lifespan=0] - How long each particle lives once emitted in ms. 0 = forever.
437443
* @param {number} [quantity=0] - How many particles to launch.
444+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
438445
*/
439446
Phaser.Particles.Arcade.Emitter.prototype.explode = function (lifespan, quantity) {
440447

441448
this._flowTotal = 0;
442449

443450
this.start(true, lifespan, 0, quantity, false);
444451

452+
return this;
453+
445454
};
446455

447456
/**
@@ -457,6 +466,7 @@ Phaser.Particles.Arcade.Emitter.prototype.explode = function (lifespan, quantity
457466
* @param {number} [quantity=1] - How many particles to launch each time the frequency is met. Can never be > Emitter.maxParticles.
458467
* @param {number} [total=-1] - How many particles to launch in total. If -1 it will carry on indefinitely.
459468
* @param {boolean} [immediate=true] - Should the flow start immediately (true) or wait until the first frequency event? (false)
469+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
460470
*/
461471
Phaser.Particles.Arcade.Emitter.prototype.flow = function (lifespan, frequency, quantity, total, immediate) {
462472

@@ -486,6 +496,8 @@ Phaser.Particles.Arcade.Emitter.prototype.flow = function (lifespan, frequency,
486496
this.start(false, lifespan, frequency, quantity);
487497
}
488498

499+
return this;
500+
489501
};
490502

491503
/**
@@ -497,6 +509,7 @@ Phaser.Particles.Arcade.Emitter.prototype.flow = function (lifespan, frequency,
497509
* @param {number} [frequency=250] - Ignored if Explode is set to true. Frequency is how often to emit 1 particle. Value given in ms.
498510
* @param {number} [quantity=0] - How many particles to launch. 0 = "all of the particles" which will keep emitting until Emitter.maxParticles is reached.
499511
* @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. This can never exceed Emitter.maxParticles.
512+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
500513
*/
501514
Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity, forceQuantity) {
502515

@@ -533,6 +546,8 @@ Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, f
533546
this._timer = this.game.time.time + frequency * this.game.time.slowMotion;
534547
}
535548

549+
return this;
550+
536551
};
537552

538553
/**
@@ -682,19 +697,23 @@ Phaser.Particles.Arcade.Emitter.prototype.destroy = function () {
682697
* @method Phaser.Particles.Arcade.Emitter#setSize
683698
* @param {number} width - The desired width of the emitter (particles are spawned randomly within these dimensions).
684699
* @param {number} height - The desired height of the emitter.
700+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
685701
*/
686702
Phaser.Particles.Arcade.Emitter.prototype.setSize = function (width, height) {
687703

688704
this.area.width = width;
689705
this.area.height = height;
690706

707+
return this;
708+
691709
};
692710

693711
/**
694712
* A more compact way of setting the X velocity range of the emitter.
695713
* @method Phaser.Particles.Arcade.Emitter#setXSpeed
696714
* @param {number} [min=0] - The minimum value for this range.
697715
* @param {number} [max=0] - The maximum value for this range.
716+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
698717
*/
699718
Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
700719

@@ -704,13 +723,16 @@ Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
704723
this.minParticleSpeed.x = min;
705724
this.maxParticleSpeed.x = max;
706725

726+
return this;
727+
707728
};
708729

709730
/**
710731
* A more compact way of setting the Y velocity range of the emitter.
711732
* @method Phaser.Particles.Arcade.Emitter#setYSpeed
712733
* @param {number} [min=0] - The minimum value for this range.
713734
* @param {number} [max=0] - The maximum value for this range.
735+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
714736
*/
715737
Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
716738

@@ -720,6 +742,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
720742
this.minParticleSpeed.y = min;
721743
this.maxParticleSpeed.y = max;
722744

745+
return this;
746+
723747
};
724748

725749
/**
@@ -728,6 +752,7 @@ Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
728752
* @method Phaser.Particles.Arcade.Emitter#setRotation
729753
* @param {number} [min=0] - The minimum value for this range.
730754
* @param {number} [max=0] - The maximum value for this range.
755+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
731756
*/
732757
Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
733758

@@ -737,6 +762,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
737762
this.minRotation = min;
738763
this.maxRotation = max;
739764

765+
return this;
766+
740767
};
741768

742769
/**
@@ -750,6 +777,7 @@ Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
750777
* @param {number} [rate=0] - The rate (in ms) at which the particles will change in alpha from min to max, or set to zero to pick a random alpha between the two.
751778
* @param {function} [ease=Phaser.Easing.Linear.None] - If you've set a rate > 0 this is the easing formula applied between the min and max values.
752779
* @param {boolean} [yoyo=false] - If you've set a rate > 0 you can set if the ease will yoyo or not (i.e. ease back to its original values)
780+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
753781
*/
754782
Phaser.Particles.Arcade.Emitter.prototype.setAlpha = function (min, max, rate, ease, yoyo) {
755783

@@ -776,6 +804,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setAlpha = function (min, max, rate, e
776804
this.autoAlpha = true;
777805
}
778806

807+
return this;
808+
779809
};
780810

781811
/**
@@ -791,6 +821,7 @@ Phaser.Particles.Arcade.Emitter.prototype.setAlpha = function (min, max, rate, e
791821
* @param {number} [rate=0] - The rate (in ms) at which the particles will change in scale from min to max, or set to zero to pick a random size between the two.
792822
* @param {function} [ease=Phaser.Easing.Linear.None] - If you've set a rate > 0 this is the easing formula applied between the min and max values.
793823
* @param {boolean} [yoyo=false] - If you've set a rate > 0 you can set if the ease will yoyo or not (i.e. ease back to its original values)
824+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
794825
*/
795826
Phaser.Particles.Arcade.Emitter.prototype.setScale = function (minX, maxX, minY, maxY, rate, ease, yoyo) {
796827

@@ -824,6 +855,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setScale = function (minX, maxX, minY,
824855
this.autoScale = true;
825856
}
826857

858+
return this;
859+
827860
};
828861

829862
/**
@@ -832,6 +865,7 @@ Phaser.Particles.Arcade.Emitter.prototype.setScale = function (minX, maxX, minY,
832865
*
833866
* @method Phaser.Particles.Arcade.Emitter#at
834867
* @param {object|Phaser.Sprite|Phaser.Image|Phaser.TileSprite|Phaser.Text|PIXI.DisplayObject} object - The object that you wish to match the center with.
868+
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
835869
*/
836870
Phaser.Particles.Arcade.Emitter.prototype.at = function (object) {
837871

@@ -846,6 +880,8 @@ Phaser.Particles.Arcade.Emitter.prototype.at = function (object) {
846880
this.emitY = object.world.y + (object.anchor.y * object.height);
847881
}
848882

883+
return this;
884+
849885
};
850886

851887
/**

0 commit comments

Comments
 (0)