4
votes

When looking to preload assets, images, audio, SKTextures etc. within a Sprite Kit game is it enough to preload to a strong iVar so that the assets are cached by iOS for the future and then just letting the game pull them from the cache behind the scenes. Or ... is it best to load the assets to strong iVars in a singleton that can be directly accessed anywhere within the game?

2

2 Answers

4
votes

I'm not sure if/how SpriteKit caches the resources behind the scenes, but the Apple Adventure example game preloads assets to static variables. So I'd probably follow their lead.

3
votes

If you use instruments you can see how much spritekit actually caches (it's a lot). So I don't think you'll see any performance increase through using a singleton to hold your assets. With that said I still use a singleton for ease of programming and hotswapping stuff like fonts and textures.

The biggest performance increases you'll see is by:

  • Using texture atlases
  • Not using apples recommended "find nodes by name" method, but using either your own arrays or ivars to find them. Personally I've never used NSHashTable (I'm on osx) and NSMapTable as much as I've done after starting spritekit.