2

Here is my problem: Despite doing these:

1) Preloading all of my texture atlases

2) Having my atlases stored in Singletons so they are not disposed of by ARC

3) Having all my animation arrays stored in Singleton

SpriteKit STILL has a short "lag jitter" when adding enemies to my scene ONLY the first time they are added. After the texture is drawn once, it never lags again when that texture is added to the scene. Memory can be seen going up when the textures are drawn on the screen finally, which looks like they aren't getting preloaded.

I am currently preloading ALL of my texture atlases in my AppDelegate on startup using...

        SKTextureAtlas.preloadTextureAtlases(primaryAtlas, withCompletionHandler: { () -> Void in

        })

primaryAtlas is an array of all 4 of my atlases which are stored in a Singleton.

Let me point out some things I have already tried and what my current setup is.

1) The array of frames for my animations are stored in Singletons and get their images from the Atlases which are in a different singleton. They used to be in the same Singleton.

2) I've tried storing ALL my textures in a Singleton which were all loaded from the atlases. But currently my animations are stored, while my single textures are functions that fetch that texture from the atlases.

3) I've turned off all animations for enemies (don't run the SKAction) and the jitter still happens when they're added and not animating.

I've been trying to fix this for a very long time and there honestly doesn't seem to be a solution.

There seems to be a similar StackOverflow question I found here with no answer: Spritekit: First texture draw slow (preloaded)

Here is a picture of some analysis I did with Instruments. Instruments capture

Community
  • 1
  • 1
datWooWoo
  • 843
  • 1
  • 12
  • 42
  • just try to preload texture and enemy in different thread don't use same thread when your texture are loaded full add a new thread and enemy using that thread or can you share your code. – dragoneye Dec 08 '15 at 06:15
  • Tried it. Doesn't work. I don't understand this. I ran it on a background thread yet it still jitters on the first draw. – datWooWoo Dec 09 '15 at 05:03
  • @lespommes Were you able to find a solution to this? I'm experiencing the same thing (iOS 9+). – damirstuhec Sep 13 '16 at 17:57
  • I was not unfortunately man. Literally not a single person could help me or suggest a "standard class pattern" for texture management that works. I wasted tons of time and eventually just released it with the jitters as I was out of ideas. My advice? Learn Unity. SpriteKit really isn't worth the trouble. I won't be using it again. – datWooWoo Oct 07 '16 at 22:07

1 Answers1

0

Make sure that your texture atlases are used as singleton class properties, because if you create variables of texture atlases inside method scope which do preloading, they will be deallocated after method returns