How do you stop a particle effect? (SKEmitterNode)

John B picture John B · Apr 6, 2014 · Viewed 9.6k times · Source

I currently have this code in a collide statement where if collide with object then this particle happens but how do I stop it? As it goes on forever whereas I only want to happen a couple of times per contactetc

SKEmitterNode *emitter =  [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle]     pathForResource:@"ff" ofType:@"sks"]];
emitter.zPosition = 0;
emitter.particlePositionRange = CGVectorMake(0, self.size.height);
emitter.position = CGPointMake(self.size.width, self.size.height/2);
[self addChild:emitter];

Answer

Nino picture Nino · Apr 6, 2014

When you use the particle-editor you can set the maximum number of particles to create. It's the field below "Particle Texture".The official description is:

"The maximum number of particles that the emitter creates over the emitter’s lifetime. After this number is reached, no more particles are created by the emitter. Enter 0 to remove particle limits."

Also see: Particle Emitter Editor Guide

Of course, you should remove the emitter-node from its parent after it created the maximum number of particles. This can be done by creating an action-sequence that waits for a few seconds and removes the emitter-node from its parent [SKAction removeFromParent].