Image sets in xcassets texture assets not loading

I’m using XCAssets texture atlases to store different versions of a game character, like so:

Characters.xcassets:

- HeroPirate sprite atlas:

- - HeroIdle (separate sets for iPhone, iPad, Apple TV and OSX, not using Universal)

- - HeroWink

- - HeroWalkLeft

- - HeroWalkRight

- HeroCowboy sprite atlas:

- - HeroIdle

- - HeroWink

- - HeroWalkLeft

- - HeroWalkRight

- Hero

I would expect that calling


let atlas = SKTextureAtlas(named: “HeroCowboy”)


would load all HeroCowboy textures when placing a breakpoint after the statement and using quick look to see the atlas’ contents.


However, depending on the Deployment Target (I’ve tried 8.0, 9.0 and —in Xcode 7.2 beta 3— 9.2) the atlas either contains one or three out of eight.


With “Provides Namespace” in the atlas options set to off (the default), I see many “The image set name “HeroIdle” is used by multiple image sets” warnings, suggesting sprite atlases are automatically combined by Xcode. These warnings disappear when “Provides Namespace” is turned on (the sprite atlas folders become blue instead of yellow), but did not solve the issue. Renaming the sprites to unique names did not solve the issue (suggesting the issue might not be related to reusing image set names).


I noticed DemoBots only uses Universal (@1x, @2x and @3x) and Mac (@1x and @2x) image sets for xcassets sprite atlases.


Is there something obvious I'm doing wrong or should I only use Universal and Mac in xcassets texture atlases, like DemoBots, or should I perhaps go back to .atlasc folders?

Replies

Upon closer inspection of the build, I noticed xcassets texture atlasses are bundled in the assets.car file.


The good new is that the atlas images itself are generated correctly. Using the Asset Catalog Tinkerer tool I can see the atlases with all textures correctly stored in the atlas.


The bad news: I am unable to access the atlas' .plist file, which would be helpful for debugging (I expected the private CUICatalog's _baseAtlasKeyForName: to return the dictionary, but haven't been successful retrieving the plist so far).


The weird thing: it seems that every single image in every sprite atlas is copied into assets.car as a separate image file as well. The images in the first sprite atlas Xcode encountered are stored using the original file name, consequent variants are stored as <Atlasname>/<filename>.


Perhaps CUICatalog's allImageNames is parsing the sprite atlasses in the background and returning the individual sprites as well as the atlas, but that wouldn't explain why only the images in the first sprite atlas are stored as <filename> instead of <atlasname>/<filename>.


Any thoughts?