2

I'm trying to make a texture atlas for a sprite kit animation, and all my frames are in pdf format.

This (or something) doesn't seem to work:

SKTextureAtlas(named: "my-atlas-name")

contains no textures.

I should probably try the same setup with a different format (e.g. PNG) to check if the fault is elsewhere, but I've searched and haven't found any specific discussions about format, especially PDF, so I thought I'd ask for future reference.

Do texture atlases work with PDFs?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Phlippie Bosman
  • 5,378
  • 3
  • 26
  • 29

2 Answers2

1

Yes we can use PDF with SKTextureAtlas. Instead of putting your pdf files in a .atlas folder, you have to use asset catalog.

In assets catalog, add a "New Sprite Atlas", a new folder will be created. Then drag your PDF files into that folder, set their Scales to "Single Scale", done.

As described in the official documentation, asset catalog is the preferred way of creating texture atlas.

Kelvin
  • 1,082
  • 2
  • 12
  • 23
0

For more about texture atlases go here

https://developer.apple.com/library/ios/recipes/xcode_help-texture_atlas/AboutTextureAtlases/AboutTextureAtlases.html#//apple_ref/doc/uid/TP40013290-CH2-SW1

PDF does load in Xcode and can be used it seems. I quickly tried to import one into a project and use it in an animation and it didn't seem to load in an animation. So I'm not sure.

Keep in mind Sprite Kit itself may not be able to use PDF even if Xcode can.

I tried to load a PDF document though. Stick with PNGs.

I'd probably go with using .PNG because they have been pretty reliable for me.

  1. To make a texture atlas you can make a new folder on you computer with the name convention nameofthetextureatlas.atlas .

  2. Put your images in that folder.

  3. Drag it into your Xcode project navigator sidebar

  4. Ensure Add to Targets is checked , Create folder references is checked, & Add to targets is checked.

Then to animate an SKSpriteNode you can do something along the lines of

    var textureArray = [SKTexture]()

    textureArray.append(SKTextureAtlas(named: "name of atlas").textureNamed("Name of Frame 1"))
    textureArray.append(SKTextureAtlas(named: "name of atlas").textureNamed("Name of Frame 2"))

    self.runAction(SKAction.animateWithTextures(textureArray, timePerFrame: 1))

Note: filenames do not include .atlas or .PDF at the end and always give files unique names.

Corey F
  • 621
  • 4
  • 14
  • _"Keep in mind Sprite Kit itself may not be able to use PDF even if Xcode can."_ This is the part that I wanted a definite answer to. – Phlippie Bosman Aug 02 '16 at 08:45