Jump to content

Adding an emitter to a group


bobonthenet
 Share

Recommended Posts

Should it be possible to create emitters in a loop and then add them to a group? I'm trying to use particle emitters as explosions and I might need to fire off multiple at a time. I figured I would use basically the same strategy used with bullets. Maybe there is a better strategy?

this.explosions = this.add.group();
let particles;
let emitter;
for(let i=0; i<3; i++) {
  particles = this.add.particles('spark');
  emitter = particles.createEmitter();
  emitter.setSpeed(200);
  emitter.setBlendMode(Phaser.BlendModes.ADD);
  emitter.on = false;
  this.explosions.add(emitter); //this line causes an error.
}

 

Link to comment
Share on other sites

It looks as if when I already have an explosion in process and then a second is fired, then the second explosion would not be complete. It looks as if the first explosion has taken up a portion of the duration of the second explosion. Here is the code I am using for my explosions, maybe this isn't the best strategy.

....
create() {
  //Particles and emitter are created in the create method.
  const particles = this.add.particles('spark');
  this.emitter = particles.createEmitter();
  this.emitter.setSpeed(200);
  this.emitter.setBlendMode(Phaser.BlendModes.ADD);
  this.emitter.on = false;
}

...

//This explosion method is called inside the colliding sprites death method.
explosion(x, y) {
  this.emitter.setPosition(x, y);
  this.emitter.on = true;
  this.time.delayedCall(1500, function(){
    this.emitter.on = false;
  }, [], this);
}

P.S. @samme I love brunch now! Thanks for sharing your starter project.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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