2

My question is for apps written in cocos2d v1.1.0-beta2b for ios:

What are the best practices for removing/releasing a CCParticleSystem?

One way I know of is using setAutoRemoveOnFinish:YES.

[emitter setAutoRemoveOnFinish:YES];
[emitter stopSystem];

Another way is removing the emitter manually using removeChild.

Are there any others? Which way is usually recommended?

As a side note, are there any known issues regarding CCParticleSystem removal/release under cocos2d v1.1.0-beta2b?

am1987
  • 347
  • 3
  • 13

1 Answers1

1

To remove a particle system, just remove it from its parent node. It's the best way.

If your particle system doesn't have a infinite duration, the best way is use setAutoRemoveOnFinish. It will automatically remove the system from parent node when particle system ends.

If your particle system have a infinite duration, then use removeChild with cleanUp:YES (you dont need to set stopSystem before). This way the system is removed forced.

Or you can use stopSystem with setAutoRemoveOnFinish:YES, and the system will be removed after the last particle ends. This way the system is removed smoothly.

Other tips:

  • Use CCParticleSystemQuad instead of CCParticleSystem.
  • Is recommended that you create your particle system using an autorelease constructor, like [CCParticleSystemQuad particleWithFile:] or [CCParticleSystemQuad particleWithTotalParticles:].
  • And, of course, use release if you have a property retaining it.
Bivis
  • 1,320
  • 1
  • 10
  • 24
  • are you sure this is correct? "stopSystem won't remove the particle system. It will stop it, but the system will remains as child. IMPORTANT: If you stop the system, it will not be removed by setAutoRemoveOnFinish, because it is stopped and will not finish." – AJ222 Jul 14 '13 at 18:12
  • Yes! 'stopSystem' will "pause" the system. And it can be restarted again with 'resetSystem'. – Bivis Jul 14 '13 at 19:28
  • I looked into it and it seems likes this is not true, since the emitter does get removed. I saw in the ccparticlesystem code that the condition for removal using the autoRemoveOnFinish property is: if( particleCount == 0 && autoRemoveOnFinish_ ). stopSystem would make the particleCount to be 0 after a few seconds (depending on the particle lifespan, as no more particles will be emitted). I think this is supposed to be the way to remove an emitter in a "nice" way, animation-wise (it will look better than to "yank" out the particle system, along with all living particles, with removeChild). – am1987 Jul 15 '13 at 05:23
  • Sorry, i looked at the CCParticleSystem code and you're right! stopSystem will remove the particle system after lifespan of the last particle. I've edited the answer. Thanks! – Bivis Jul 15 '13 at 17:05