0

I am attempting to swap a character in a game that does not move to a gif image that does move.

Currently, the code is

    let player = Witch(imageNamed: "player")

When I attempt to change the image to the gif by changing names, as expected, it does not work. How can I change, or add to, the code above to play the gif recurringly as the spriteNode's image that is the character? I want it to be able to be one or two lines, if possible. I have used

     var runAnimation = [SKTexture]()

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let playerNode = self.childNode(withName: "player")
    if(playerNode != nil){
        let animation = SKAction.animate(with: runAnimation, timePerFrame: 0.1)
        playerNode?.run(SKAction.repeatForever(animation))
    }
}

     let runAtlas = SKTextureAtlas(named: "run")
    for index in 1...runAtlas.textureNames.count{
        let textureName = String.init(format: "run%1d", index)
        runAnimation.append(SKTexture(imageNamed: textureName))
    }

but have received the error of

    Thread 1: Fatal error: Can't form Range with upperBound < lowerBound

If you can help, please let me know.

Amber
  • 5
  • 2
  • Possibly Related: https://stackoverflow.com/questions/33338706/simple-gif-like-animation-with-spritekit – Ahmad F May 29 '18 at 01:12
  • The implication of your error is that `runAtlas.textureNames.count` is zero. Also you do know that the first index is `0`, not `1`, right? – matt May 29 '18 at 03:07
  • @matt Yes, I know it is 0 and not 1, but I accidently typed a 1 when I made this. – Amber May 29 '18 at 15:12

0 Answers0