Burundanga
Burundanga

Reputation: 668

How to animate sprites without texture atlases

As I know iOS 9 is transforming atlases into something horrible now so I don't want to use it. At least before they'll fix the issue. I need to animate a hand and am trying to do this without atlases. However it crashes on me for some reason. I have my textures in images.xcassets. That's what I do:

var leftHand = SKSpriteNode()
var leftArmAnimationArray = ["1l", "2l", "3l", "4l", "5l"]

func addLeftHand() {
   leftHand = SKSpriteNode(imageNamed: "1l")
   leftHand.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
    addChild(leftHand)
}

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)
        switch self.nodeAtPoint(location) {
        case self.leftHand:
leftHand.runAction(SKAction.animateWithTextures(leftArmAnimationArray, timePerFrame: 0.3))
    }
  }
}

It crashes and shows me SIGABRT. What am I doing wrong? Is that possible to animate sprites in SpriteKit without .atlas?

Upvotes: 0

Views: 121

Answers (1)

beyowulf
beyowulf

Reputation: 15331

Think you need to say something like SKTexture(imageNamed: "1l"),SKTexture(imageNamed: "2l") for each of the items you place in leftArmAnimationArray right now it's just an array of strings, should be array of textures.

Upvotes: 1

Related Questions