Jump to content

Weird problem with emitter


Recommended Posts

Hi there,

I have a problem with an emitter, I´m making a shoot´em up and one of the weapons I have is something like a circular explosion (see the picture), shooting 20 bullets but the game get slower and slower, so I check the emitter and instead of 20 bullets it seems is shooting 1050 each time I use it. Also, everytime I shoot I´m adding 1050 bullets instead of reusing them, so I guess I should use something else instead of start()

I´m always having problems with the emitter, it seems that I don´t understand them really well (is even worse with the Particle Storm plugin!)... so, can anyone tell me why the hell is happening this? I have no idea...

    this.myEmitter = this.game.add.emitter();
    var EXPLODE_DIAMETER = 20.0;
    this.myEmitter.x = this.mySprite.x - EXPLODE_DIAMETER/2;
    this.myEmitter.y = this.mySprite.y - EXPLODE_DIAMETER/2;
    for (var i = 0; i <= 360; i=i+18) {
        var xsp = Math.cos(2 * Math.PI * i / 360.0) * EXPLODE_DIAMETER * 20;
        this.myEmitter.setXSpeed(xsp, xsp);
        var ysp = Math.sin(2 * Math.PI * i / 360.0) * EXPLODE_DIAMETER * 20;
        this.myEmitter.setYSpeed(ysp, ysp);
        this.myEmitter.gravity = 0;
        this.myEmitter.minParticleScale = 0.5;
        this.myEmitter.maxParticleScale = 0.5;
        this.myEmitter.start(true, 2000, null, 1);

console.log(this.myEmitter.children.length)//IT ADDS 1050 evertime I .start() the emitter


Link to comment
Share on other sites

3 minutes ago, drhayes said:

The default number of particles in an emitter is 50. You've got an off-by-one error in your loop (double-counting 0 and 360), so there's 21 iterations. 21 * 50 = 1050.


Oh, ok, now I know that... but anyway, why is releasing 50 particles if I´m telling it just to relase one in the fourth parameter of the start() method?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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