Adding an emitter to a group

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 =;
let particles;
let emitter;
for(let i=0; i<3; i++) {
  particles = this.add.particles('spark');
  emitter = particles.createEmitter();
  emitter.on = false;
  this.explosions.add(emitter); //this line causes an error.


Share this post

Link to post
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.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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.