Jump to content

Repeated calls to Emitter.start spawns increasing number of particles


Recommended Posts

In [both 1.1.4 and] 1.1.5 it seems that repeated calls to Emitter.start with the same quantity argument (no exploding) causes an increasing number of particles to be generated each call, rather than generating the indicated number of particles for that call.


For example: I make 200 particles once (with makeParticles), then at set intervals want to spawn 5 particles. When these intervals have elapsed I call start(false, 0, 250, 5) to release 5 of the particles. After the first interval, 5 sprites are spawned. After the next interval, an additional 10 sprites are spawned (so there are 15 total), but I only wanted 5 more. Every interval, 5 more sprites are spawned that single call, leading to an geometric increase in the number of particles on the screen.


If I use the explode property (call start(true, 0, null, 5)) then only five particles are spawned each time, as I would expect.


This is perhaps not a bug, per se, because the source for Emitter.start explicitly checks 

if (explode){    this._quantity = quantity;}else{    this._quantity += quantity;}

But I guess I am wondering why would this behavior ever be desired, and if it should really be this way?

Link to comment
Share on other sites

  • 1 year later...
Sorry to bump this one, but I have the exact same question.
I use an emitter to create a stars explosion effect when the player steps on a goal tile. This particle effect can occur more than once during a game, so I just re-use the same emitter, move it to the new location and do .start() again. Here's my code.
create: function() {    // particle on mainguy bonus    this.emitterBonus = this.game.add.emitter(0, 0, 30); // x=0, y=0, maxParticles=30    this.emitterBonus.makeParticles('particles', [2, 3, 4, 5]);    this.emitterBonus.setXSpeed(-300, +300);    this.emitterBonus.setYSpeed(-300, +300);    this.emitterBonus.setRotation(-500, +500);    this.emitterBonus.setScale(0.1, 1, 0.1, 1, 1000, Phaser.Easing.None);    this.emitterBonus.setAlpha(1, 0, 2000);    this.emitterBonus.gravity = 0; // no gravity//..pickupBonus: function(thetile) {    this.emitterBonus.x = thetile.x;    this.emitterBonus.y = thetile.y;    this.emitterBonus.start(false, 500, 1, 30); // explode=false, lifespan=500, freq=1, quantity=30}

What's the reasoning behind increasing the number of particles every time you call it with explode=false ? Even when I set the maximum number of particles to 30 and then start with quantity=30 it still increases the number of particles. So the first time it's 30 particles, then 60, 90 etc.


Btw this post mentions that is was a bug that was fixed in 2.0.6 but it looks like it's back.

Link to comment
Share on other sites

  • 2 months later...

Okay, I really want to fix this issue now to finish up a game  :unsure: here is a JSFiddle with the issue isolated and for convenience I've added some debug texts.



What I want to do is, when you click somewhere it should emit 10 particles but not all at once (explode=false).

The first time this works fine, however when you click another time the emitter adds another 10 particles so 20 in total, click another time and you've got 30 particles etc. etc.

What am I doing wrong here, can anyone point me in the right direction?

Link to comment
Share on other sites

Okay, I think I found a bug in phaser framework, but good news is it's easy to fix. :) In v2.4.4 it's in the Emitter.js file on line 531
Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity, forceQuantity) {    //.. other code omitted here    else    {        this.on = true;        // BUGFIX STARTS        //this._quantity += quantity; // old line        this._quantity = quantity;    // new line        // BUGFIX ENDS        this._counter = 0;        this._timer = this.game.time.time + frequency * this.game.time.slowMotion;    }

Also, I've submitted it as a bugfix to the official framework, it's in pull request #2170

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...