Spewing Particles Briefly for Explosions

We want to add explosions to the two collisions in our game: when the ship either shoots or collides with an obstacle. We’ll build these particle emitters the same way we built the thrust emitter. Adding them to the scene is easy, but we have a problem. We don’t want these emitters to keep running indefinitely. How do we make them die out and remove them from the scene after a short duration?

We use Sprite Kit actions, of course! Specifically, we’ll use an action sequence to pause for a short duration, and then set the particle birthrate property to zero and wait for all the particles to die before removing the node. Because this is such a common operation for our emitters in this game and we already ...

Get Build iOS Games with Sprite Kit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.