Search code examples
iosswiftsprite-kitsktextureatlas

App's second sprite atlas 'cannot be found'


I have a SpriteKit game that uses a sprite atlas (extension .spriteatlas). It's located in my Assets.xcassets. This sprite atlas works just fine. I load the atlas like this:

let atlas = SKTextureAtlas(named: "Atlas")

Now, I'm trying to add a second sprite atlas, but Xcode says "Texture Atlas 'SecondAtlas' cannot be found".

I've tried creating/adding this second one in a number of ways...creating it on my desktop and then dragging it into Xcode; creating it on my desktop and then dragging it into .xcassets via a Finder window; copying/pasting the existing, working, sprite atlas and then renaming it; etc.

I've checked and re-checked that I'm trying to load the sprite atlas using the correct folder name. I am.

I've also tried the following:

  1. Quit Xcode
  2. Reopen Xcode
  3. Open my project
  4. Clean the build folder
  5. Build/Run

No matter what I do, the sprite atlas cannot be found despite literally being right there in front of me...it shows up in Xcode and it shows up in the Finder. I'm out of ideas.

Thank you for your help!


Solution

  • Apparently you can't have identically named textures -- even if they're in separate atlases. My project had, for example, Atlas1 -> "someImage" and Atlas2 -> "someImage".

    When I renamed all the textures inside the second sprite atlas, it was found/loaded as desired.