Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell when a SKEmitterNode has reached its maximum particles?

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.

like image 517
PricklyApps Avatar asked Nov 09 '13 18:11

PricklyApps


1 Answers

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.

like image 76
LearnCocos2D Avatar answered Nov 05 '22 00:11

LearnCocos2D