Loading Particle Emitter Files

Unfortunately, loading particle emitter files into memory isn’t as straightforward as loading sound files into actions, as we saw in Playing Sound Effects in the Scene. For the moment, the Sprite Kit API doesn’t give us a single method call to load and cache the file for later reuse. But that doesn’t mean we can’t implement it ourselves!

The *.sks files are archived SKEmitterNode instances. When we manipulate what we see in the Xcode particle editor, we’re actually manipulating the real properties on this kind of node. When Xcode writes the particle emitter to disk, it uses the NSKeyedArchiver mechanism.

We can retrieve a copy of that node by loading it from the app bundle. To mimic the similar API that Apple ...

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.