jemmons
jemmons

Reputation: 18657

atlasWithName: throws "Unsupported Texture Atlas Format" exception

I'm using several texture atlases in a SpriteKit game without issue, but I've added a new one (foo.atlas) that I'm loading with the following code:

SKTextureAtlas *myAtlas = [SKTextureAtlas atlasNamed:@"foo"];

Whenever the above line is executed, an exception is thrown and the following is printed out to console:

Unsupported Texture Atlas Format Code 2

But that's it. No further details. I'll get this error even if I remove every texture from the atlas and replace it with known-good textures from one of my other atlases that work without issue. I've restarted, cleaned by build, and deleted derived data… all to no avail.

Any ideas as to why this isn't working?

Upvotes: 1

Views: 585

Answers (1)

jemmons
jemmons

Reputation: 18657

Short Version

If you include a plist in your project with the same name as your atlas (foo.plist in this example) you'll get the error above and nothing will work. Rename the plist or the atlas to something different.

Long, Tragic Version

Looking in the Resources folder of an app with atlases, one can see that the build process takes the tiles in your foo.atlas folder and combines them into one giant texture called foo.1.png. It also generates a plist file to record the coordinates of the subtextures of the atlas called (you guessed it) foo.plist.

Both foo.1.png and foo.plist are wrapped up in a folder called foo.atlasc. But apparently [SKAtlas atlasNamed:@"foo"] finds foo's plist with something broad like NSBundle's -URLForResource:withExtension:, because if you happen to have an unrelated plist named foo.plist anywhere in your resource directory, it gets loaded instead of the atlas's plist. And of course it probably doesn't conform to SpriteKit's idea of what an atlas plist should look like, so it freaks out and spits the "Unsupported Texture Atlas" error noted above.

Upvotes: 7

Related Questions