Xcode 7 Beta 4 SKTexture: Error loading image resource

Hi guys.


I am having problems with this line of code:

let background = SKSpriteNode(imageNamed: "Background")


The image's name is correct, and it is inside a folder called Fuentes/Art/backgrounds.atlas


I tried too this option:

      let atlas = SKTextureAtlas(named: "backgrounds")
      let texture = atlas.textureNamed("Background")
      let background = SKSpriteNode(texture: texture)


But then, it says: Texture Atlas 'backgrounds' cannot be found.

Any suggestions?


PD: I made triple check on every denomination for every name.

Answered by iostony in 34614022

What you suggested gave me a good idea and I solved it. I didn't what you tell me, but I decided to put the files inside Assets.xcassets directly and everything worked perfect. Even better, if you right-click over it you can create your new Sprite Atlas and put inside the elements that you want. So, this is the new way of doing things (at least at the moment).

Has the atlas been added properly to your Xcode project?


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


(In particular, step 6 "Set Enable Texture Atlas Generation to Yes." in build settings)

I got into PROJECT and tap over "Build Settings". Inside that, I tried to look for "SpriteKit Deployment Options" (using the word: "Sprite" and checking all the options), but I didnt find anything. Is there a way to add it?, because when I tap over "+" the only option I get is "Add a user define-settings" that is not what I want.


Thank you.

Accepted Answer

What you suggested gave me a good idea and I solved it. I didn't what you tell me, but I decided to put the files inside Assets.xcassets directly and everything worked perfect. Even better, if you right-click over it you can create your new Sprite Atlas and put inside the elements that you want. So, this is the new way of doing things (at least at the moment).

(Glad you solved it; since I already typed it, here's another possible solution.)


It looks like the settings have changed in Xcode 7, and the "SpriteKit Texture Atlas Options" only appear when an atlas has been added to the target.


If you select your atlas folder in the project navigator on the left side, does it have a checkmark next to the target in Target Membership in the File Inspector pane on the right side?


If checking that box to add it to your target doesn't change anything, you may need to re-add the atlas folder to the project.

I have image1, 2, 3 .... to make animation

I write it in this way:

SKSpriteNode *image = [SKSpriteNode spriteNodeWithImageNamed:@"image@%d"];

and got "Error loading image resource "image@%d" " and I changed the "@%d" to 1, 2 ... and add .png.

Xcode 7 Beta 4 SKTexture: Error loading image resource
 
 
Q