3

I think I might be using Texture Atlases incorrectly, and wanted to ask for some advice.

I found a few sites online that suggested I create a folder, let's say Ball.atlas, and in there, add my animation frames (ball1, ball2, ball3).

Then drag and drop ball.atlas into my actual Xcode content tree, and then reference that atlas in code like this:

self.ballAtlas = SKTextureAtlas(named: "ball")
self.ballImages.append(self.ballAtlas.textureNamed("ball1"));
self.ballImages.append(self.ballAtlas.textureNamed("ball2"));
self.ballImages.append(self.ballAtlas.textureNamed("ball3"));
self.ballImages.append(self.ballAtlas.textureNamed("ball4"));
self.ballImages.append(self.ballAtlas.textureNamed("ball5"));

and then I can reference self.ballImages to display the animation, etc.

I saw another guide, however, that said to simply go to your xcassets folder, and click '+', and hit 'new texture atlas', and it creates a folder. Then simply drag the ball images in there.

There is one fundamental difference here, however: in the second approach, you can specify the @1x, @2x, @3x, whereas in the first example (dragging the folder) there is no way to specify.

What should I be doing? Should I not be dragging anything, and instead simply put all atlases inside the xcassets collection?

Thanks!

mugx
  • 9,869
  • 3
  • 43
  • 55
NullHypothesis
  • 4,286
  • 6
  • 37
  • 79
  • 4
    I am voting to close, but I will answer. Stick with the xcassets folder, that is the newest method apple has given us. With it you can go beyond just @1x,@2x,@3x, and instead specify "device" specific resources. To get it working the old way, you just kept all 3 files in the same atlas path, and the system would automatically pick the correct file scale – Knight0fDragon Dec 23 '16 at 04:03
  • thanks for such a helpful answer! I don't need to name the folder .atlas or anything like that, right? Simply click '+' and add new atlas, and i'm done right? – NullHypothesis Dec 23 '16 at 04:15
  • 3
    inside xcassets, yes – Knight0fDragon Dec 23 '16 at 04:48

0 Answers0