I've solved the problem...but its really a hack. I have a SKScene
which is the parent node to all of the "trees" (SKSpriteNodes
). This scene will be adding multiple trees to itself. At first I thought that this was some sort of problem because if I only added one tree, it would display the image correctly. The answer to this question led me to believe that I would need to programmatically create a SKTextureAtlas
singleton in the (the texture is in a SKTextureAtlas
) and pass it to the tree class to get the texture from on an init method. I made a property in the SKScene
to hold the texture atlas so that I could pass it to the tree class every time I made a new one. I tried loading the texture from texture atlas (in the tree class) using the textureNamed: method. This still did not work. I switched back to loading the texture with SKTexture's textureWithImageNamed: method and it worked. Further more I changed to code back so that the tree subclass would not be sent the SKTextureAtlas
singleton at all and it still worked.
In the SKScene
I get the texture atlas using:
[SKTextureAtlas atlasNamed:@"Textures"]; //Textures is the atlas name.
and set the return value to be the SKTextureAtlas
property described above. I thought that maybe the atlas just had to initialized at some point in the code, so I tried this:
SKTextureAtlas *myAtlas = [SKTextureAtlas atlasNamed:@"Textures"];
and the following alone on one line:
[SKTextureAtlas atlasNamed:@"Textures"]
but neither worked. Apparently I need to have a property in my tree's parent class which is the SKTextureAtlas
which holds the texture which the tree uses without any reference to a SKTextureAtlas
whatsoever... Is this a glitch or something? It's working now but it feels like a hack.