3

I dragged a folder named "movementAnim" into the Image assets folder, which is suppose to create a texture atlas (from what I picked from the WWDC 2015 What's New in SpriteKit Session). See the code below:

SimpleSprite class:

Init()  {
    let spriteAtlas = SKTextureAtlas(named: "movementAnim")
    sprite = SKSpriteNode(texture: spriteAtlas.textureNamed("moveAnim01"))

    sprite.name = spriteCategoryName
    sprite.position = CGPointMake(CGRectGetMidX(screenSize), sprite.frame.size.height * 3.7)
    initialPos = sprite.position
    sprite.zPosition = 10

}

func physicsProperties  ()  {
    sprite.physicsBody = SKPhysicsBody(rectangleOfSize: sprite.frame.size)
    sprite.physicsBody?.friction = 0.4
    sprite.physicsBody?.restitution = 0.1
    sprite.physicsBody?.dynamic = false

}

In the init of the GameScene class:

simpleSprite = SimpleSprite()
addChild(simpleSprite!.sprite)
simpleSprite!.physicsProperties()

I get the following log message:

Texture Atlas 'movementAnim' cannot be found.

But when I use the following instead of the texture, it works perfectly:

sprite = SKSpriteNode(imageNamed: "newMoveAnim01")

I've crossed checked the names and made sure there are no duplicates. I am not sure what's wrong.

ErrorFree
  • 83
  • 7

2 Answers2

8

If you add the extension .spriteatlas to your folder name, it should work. XCode does not add this by default.

You are correct that atlases are done in the image assets folder now, William Hu's way was the old way it was done.

Knight0fDragon
  • 16,609
  • 2
  • 23
  • 44
2

Create a folder in your project root path, name it movementAnim.atlas, then copy and paste all your images into this folder. Then go back your project navigator and add this folder into your project, make sure the folder is blue.

William Hu
  • 15,423
  • 11
  • 100
  • 121
  • Thanks, it's working. But I thought that with Xcode 7, a folder can be copied into the image assets and an atlas will be created automatically. So why isn't that option working? – ErrorFree Jan 25 '16 at 13:45
  • I remembered i did it in the assets but not work, so i used the old work. – William Hu Jan 26 '16 at 06:33