0

In my SK Game I have rockets that fire and each one gets an SKEmitterNode that creates a smoke trail effect. Once the rocket hits something I call removeFromParent and this also removes the emitter which instantly removes the smoke trail. I want the smoke trail to stick around until the particles dissipate.

What I don't understand is why this doesn't happen even though the targetNode is set to self.scene. I have taken the emitter node, created an array with all of it's children and called count to NSLog how many children it has and gotten back.. zero. It seems as if all of the particles should be children of the scene itself, so when the emitter is removed from the scene, it's particles shouldn't be, because they aren't it's children.

I have tried many, many different ways of doing this and none of them have worked.

All I want is for each rocket to have an emitter, which leaves a smoke trail, and when the rocket is destroyed, the smoke trail remains as it dissipates. But I can't call removeFromParent on the rocket without destroying it's emitter too!

Todd
  • 143
  • 8
  • You could manually make the smoke appear to dissipate. The idea being ... Rocket hits target, force a delay, decrease amount of nodes emitted, force delay, decrease amount of nodes emitted, repeat until desired then remove emitter. You would achieve a this with a sequence of skactions. I can add an answer with code in an hour or so if you are interested in this approach. It will not require much code. – meisenman Oct 14 '14 at 01:36
  • 1
    Make the emitterNode a property of the rocket. Add the emitter as a child to the scene. When the rocket explodes, remove the rocket. Alternatively, keep the emitter as child of rocket and just set the rocket alpha to 0, which makes it completely transparent, and then remove the rocket after the emitter dissipates. – prototypical Oct 14 '14 at 01:37
  • The first approach will still not create a dissipating effect. The second approach will not create a dissipating effect either (it will have the same effect where the particles just disappear on removal of the emitter) and will also leave your rocket susceptible to contact events and collision unless you change the categoryBitMask. – meisenman Oct 14 '14 at 17:34
  • I was just solving the first issue. Obviously, if he wants to ramp it down, he has to do that via code reducing particleBirthRate. Changing the collision state is also a given. Both my solutions solve the question in the subject. Each additional should be made into individual questions imo. Not looking to code his game for him, which is why I just gave suggestions for solving the initial issue. Both will indeed work. Keeping emitter particles after emitter removed -- not possible. – prototypical Oct 14 '14 at 19:50

1 Answers1

0

I have finally figured out how to do this, but it took some fiddling and there are some things I still don't quite get. However, it works.

I had to create several emitters. My heli can shoot X number of rockets before having to reload (which takes a while), so I just created that many emitters as iVars. Therefore, each rocket would have its own emitter.

Still, I couldn't add the emitter as a child of the rocket or it would be destroyed when the rocket was. So, in my update method, I created a switch statement. I created a new iVar int to hold an indicator for which emitter was being used. In each switch case I would tell Sprite Kit to take that emitter and place it right behind the rocket.

Therefore, whenever the rocket was in flight, the switch statement would check for which emitter should be "attached" to the rocket and update its position every frame. The end result is an emitter that stays attached to the rocket but isn't a child.

Then, in my didBeginContact method, I destroy the rocket upon contact and tell it's emitter to stop emitting particles (with setNumParticlesToEmit:1).

When the heli goes through it's reload, I remove all of the emitters from their parents so they can be reassigned later.

Finally, I had to resetSimulation on each rocket fire so that a large smoke trail wouldn't instantly appear.

That's how I got it to work.

Todd
  • 143
  • 8