Best way to destroy a sprite after animation in a simple way

I have a sprite that is created every time an explosion happens, I need that, after the animation ends, the sprite is destroyed. What’s the best way to do this? I’m currently using this:

  this.anims.create({
  	key: 'explodeAnimation',
		frames: this.anims.generateFrameNumbers('explosion', { start: 0, end: 11 }),
    frameRate: 13,
    hideOnComplete: true
  })

hideOnComplete” works very well, but I’m pretty sure it’s not the best approach as it just hides the sprite and doesn’t remove it completely, I believe this can hurt my game’s performance… Isn’t there something like “destroyOnComplete”?

1 Like

No, but you could use the animation complete event for that.

Another way is to create sprites ahead of time, hide them, and then use showOnStart and hideOnComplete together.

1 Like

My game is multiplayer, will have several players shooting at the same time. In terms of performance, would it be more feasible to create the sprites and then destroy them? or create and then hide them? By logic it would make more sense to keep them hidden, but I worry about the amount of sprites that will be in play simultaneously, how harmful can this be? Should I be concerned?

OBS: I’m talking about 100 bullets for each player, each bullet has a sprite of approximately 40 pixels

It’s usually more efficient to create them upfront and then recycle (show/activate and hide/deactivate).

1 Like