0

I have been using SpriteKit for a year now, and am very comfortable with it. However much of what I do is habitual, and I am not necessarily sure of why I do some things. My images are all sorted in texture atlases, but there appears to be 3 different ways of outputting these sprites. Could someone explain the differences in presenting sprites in SpriteKit using objectiveC. Is there a performance difference? Does one of the methods cache the sprite? Or does it even make any difference?

SKSpriteNode *tap = [SKSpriteNode spriteNodeWithImageNamed:@"tap"];

vs.

SKTexture *tapTexture = [SKTexture textureWithImageNamed:@"tap"];
SKSpriteNode *tap2 = [SKSpriteNode spriteNodeWithTexture:tapTexture];

vs.

SKTexture *tapTexture2 = [[SKTextureAtlas atlasNamed:@"Sprites"] textureNamed:@"tap"];
SKSpriteNode *tap3 = [SKSpriteNode spriteNodeWithTexture:tapTexture2];
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Ron Myschuk
  • 6,011
  • 2
  • 20
  • 32

1 Answers1

0

It's all the same. If there are any performance differences they are probably minute. Still, if you already have a texture you can avoid the file/cache lookup costs by using the withTexture initializers.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Thanks for the reply Steffen, I was aware of reusing the SKTextures, but it's good to know that there is no performance penalty whichever option I choose. – Ron Myschuk Jan 17 '15 at 16:12