5

When using a SKEmitterNode with a maximum particles set to a number the documentation says that it will stop generating particles. My question is, is there a way to tell that this has happened? I want to remove the particle emitter from the scene when it has done its job.

san
  • 3,350
  • 1
  • 28
  • 40
PricklyApps
  • 113
  • 6

2 Answers2

7

You can calculate when the emitter is done.

For example if numParticlesToEmit is set to 1000 and the particleBirthRate is 100, then the particle will be done emitting new particles after 10 seconds. You then have to add particleLifeTime with half of particleLifeTimeRange to account for the time particles will remain on the screen. After that, the emitter is not only done emitting new particles but also the last and/or longest-living emitted particle will have been removed from the screen.

Assuming em is your emitter:

CGFloat seconds = em.numParticlesToEmit / em.particleBirthRate + 
                  em.particleLifetime + em.particleLifetimeRange / 2;

You can then perform a selector with wait time or run an action with the given delay to be notified when the particle emitter is done.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Far better solution, I totally misread the question and for some reason was thinking that the numParticlesToEmit was unknown. Math is wonderful. – prototypical Nov 11 '13 at 03:00
0

I am not able to find a way to check the active particle count. I was thinking maybe it was possible with the children property it inherits from SKNode, but that doesn't work.

I noticed the particleAction property for an SKEmitterNode which has this blurb :

Adding complex actions to particles can severely impact the performance of the particle emitter. Also, because the particles do not exist as an explicit node that you can manipulate, you cannot remove the actions from existing particles.

It's possible that you can utilize SKAction performSelector to notify you of active particles. When that stream ends, then you could assume there are no particles remaining.

Not a very elegant or ideal solution by any means, and I myself would be interested in a better solution for sure.

prototypical
  • 6,731
  • 3
  • 24
  • 34