Reputation: 1805
Why would I want to do one of these options over the other... I guess, I don't understand how they differ beyond what I have to code
-make a texture atlas named "HeroSprites.atlas" in Xcode with the image "Hero.png" and possibly other variations in it.
Example 1:
SKSpriteNode* heroSprite = [SKSpriteNode spriteNodeWithImageNamed:@"Hero"];
//pulls in image from the atlas without having created an atlas object first
[self addChild: heroSprite];
Example 2:
SKTextureAtlas* heroAtlas = [SKTextureAtlas atlasNamed:@"HeroAtlas"];
SKSpriteNode* heroSprite = [SKSpriteNode spriteNodeWithTexture:[heroAtlas textureNamed:@"Hero"]];
//pulls in image from the atlas after having created an atlas object first
[self addChild:heroSprite];
As far as I can tell, both seem to load the atlas into memory so that I can call upon all the images within. The only reason I can think for this is if there were identical image names in separate atlases, but it would be easy enough to avoid that.
Upvotes: 0
Views: 1735
Reputation: 4447
A SKTextureAtlas can improve memory usage and rendering performance. For example, if you have a scene with sprites drawn with different textures, Sprite Kit performs one drawing pass for each texture. However, if all of the textures were loaded from the same texture atlas, then Sprite Kit can render the sprites in a single drawing pass—and use less memory to do so. Whenever you have textures that are always used together, you should store them in an atlas.
Upvotes: 1
Reputation: 2576
Here is what you should know about SKTextureAtlas:
Upvotes: 1