iosobjective-csprite-kitsktexturesktextureatlas

Preloading SKTextures/SKTextureAtlas confusion


I've read all of the posts on here regarding this topic and none of them seem to answer my question.

My question is when is a SKTexture/SKTextureAtlas loaded into memory?

From what I've read you need to keep strong a reference to any SKTexture or SKTextureAtlas loaded into memory with [SKTexture preloadTextures: withCompletionHandler:] so that it won't get released with ARC, Which makes sense to me because the object will get released at the end of the method when nobodies retaining it. What I don't understand is how a SKTexture with a strong pointer retaining it isn't loaded into memory, wouldn't this make [SKTexture preloadTextures: withCompletionHandler:] redundant and unnecessary since the textures already loaded in memory. I'm obviously missing something so any insight would be great.

Cheers!


Solution

  • The SKTexture Class Reference explains it like this:

    The texture data is loaded when:

    The size method on the texture object is called.

    Another method is called that requires the texture’s size, such as creating a new SKSpriteNode object that uses the texture object.

    One of the preload methods is called (See Preloading the Texture Data.)

    The texture data is prepared for rendering when:

    A sprite or particle that uses the texture is part of a node tree that is being rendered.

    Once the SKTexture object is ready for rendering, it stays ready until all strong references to the texture object are removed.