0

我正在尝试将游戏中的角色交换为不会移动的 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

如果你能帮忙,请告诉我。

4

0 回答 0