如何在swift中添加gif作为imageNamed项?

时间:2018-05-29 01:05:20

标签: swift gif imagenamed

我正在尝试将游戏中的角色交换为不移动到移动的gif图像。

目前,代码是

    let player = Witch(imageNamed: "player")

当我尝试通过更改名称将图像更改为gif时,正如预期的那样,它不起作用。 我如何更改或添加上面的代码来重复播放gif作为spriteNode的角色图像?如果可能的话,我希望能够成为一两行。我用过

     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))
    }

但收到错误

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

如果您能提供帮助,请告诉我。

0 个答案:

没有答案