Jump to content

Destroy Emitter Particle on Click

Mark Kirkman

Recommended Posts

Hi all, this is my first post here.

I have created a game with emitter particles that flow up from the bottom of the game canvas. My question is I want to destroy the partial (sprite) onClick which will in turn give a set value to the score. I cannot for the life of me work out how to destroy the particle on click. any help would be greatly appreciated as I cannot find any documentation specifically for this.

Any advice would be greatly appreciated, as I am unsure if the emitter is the best way to achieve what I want.


emitter =  this.emitter = this.game.add.emitter(this.game.world.centerX, this.game.world.centerY);
        //    This emitter will have a width of 800px, so a particle can emit from anywhere in the range emitter.x += emitter.width / 2
        emitter.width = 900;
        emitter.height = 200;    
        emitter.y = 1200;
        emitter.minParticleSpeed.set(0, 10);
        emitter.maxParticleSpeed.set(0, -80);
        emitter.setRotation(20, -60);
        emitter.setAlpha(1, 1);
        emitter.setScale(1,1, 0.5, 0.5);
        emitter.gravity = 0;
        emitter.flow(4000, 100, 100, -1);
        //  This will emit a quantity of 5 particles every 500ms. Each particle will live for 2000ms.
        //  The -1 means "run forever"
        emitter.start(false, 4000, 500, 15, true);    

Link to comment
Share on other sites

The Phaser.Particle class extends from Phaser.Sprite. Phaser.Sprite has a property called "inputEnabled" that makes the sprite start registering click events. I think if you set inputEnabled to true the particle will start processing click events. Then it's a matter of adding listeners to the events.onInputDown (or whatever) event. You probably want "addOnce" instead of "add" for the onInputDown signal, too, since they get removed from the game once they're clicked.

That means you say "emitter.setAllChildren('inputEnabled', true;" to turn it on. Then I *think* you can say "emitter.callAll('events.onInputDown', 'emitter.events', myListenerFunction);" to get the listeners assigned.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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