4

I'm having a performance issue regarding Apple Spritekit Framework. I use the method preloadTextureAtlases:withCompletionHandler: of SKTextureAtlas to make sure all my textures are loaded before the game really starts.

Yet when the first texture of this atlas (whatever it is) is added to the scene as a child I got a small lag, like if the texture wasn't loaded. It only happens the first time.

I tried real hard to debug this and to find the reason but I couldn't find it. Looking with Instrument and the Time Profiler I got this

Time Profiler

Which seems strange since my texture atlas contains all the allocated textures (and they are still allocated). Why does it call a load method ? Maybe it's something related to OpenGL like the texture binding.

I'm sure this correspond to the frame where my object is allocated (see the spike on the right). Nothing else is allocated or in motion here.

Time Spike

I'm really stuck on this and any help would be deeply appreciated. Thanks for your time.

genpfault
  • 51,148
  • 11
  • 85
  • 139
ophilbert
  • 199
  • 1
  • 9
  • If you preload textures but aren't actually using them afterwards, Sprite Kit may uncache the atlas. Be sure to keep a strong reference to at least one of the textures in the atlas, and do so in the completion handler. You could for a quick test create a sprite with an atlas texture and add it to the scene and set its hidden state to NO in the completion handler. – CodeSmile Mar 10 '14 at 18:22
  • I have subclasses of SKSpriteNode that use a texture and adding an hidden SKSpriteNode does not solve the problem. Using the subclass does the work but it seems to be a dirty way to fix this. I don't know what SKTexture load as it's not documented but the SKTexture doc declared 2 phases: - texture data loading - texture data prepared for rendering I'm going to work on it and come back if find a cleaner way to fix this. – ophilbert Mar 10 '14 at 21:59
  • 1
    Did you ever find a fix for this? This is happening to me too and it makes absolutely no sense. I'm preloading all my texture atlas' on startup and keep instances of them in a Singleton so they shouldn't be releasing. When my game starts, there's a slight jitter lag ONLY when the texture first appears. – datWooWoo Dec 08 '15 at 02:59
  • I stopped using SpriteKit as I no longer work on this project and I don't remember finding a fix for it, it was a long time ago and SpriteKit was a few months old. There must be a fix for this however. – ophilbert Dec 18 '15 at 18:25

0 Answers0