ios - 如何跟踪 Sprite Kit 中的动画

标签 ios swift animation sprite-kit

我需要跟踪带有纹理的动画。我正在为电源条设置动画,当用户单击屏幕时它应该停止并节省电量。我不知道如何省电。到目前为止我有这个:第一次触摸电源条动画,但在第二次触摸时它只停止但不节省电量。

这是我创建动画的方式:

textureAtlas = SKTextureAtlas(named:"images")
        for i in 1...textureAtlas.textureNames.count{
            let name = "\(i).png"
            textureArray.append(SKTexture(imageNamed: name))
        }
 let animateForward = SKAction.animate(with: textureArray, timePerFrame: 0.1)
        let animateBackward = SKAction.reversed(animateForward)
        let sequence = SKAction.sequence([animateForward,animateBackward()])

这是我检测触摸的方式:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if let firstTouchStorage = touches.first{ // after first touch
        let animateForward = SKAction.animate(with: textureArray, timePerFrame: 0.1)
        let animateBackward = SKAction.reversed(animateForward)
        let sequence = SKAction.sequence([animateForward,animateBackward()])
        arrow.removeAllActions()
        arrow.run(SKAction.repeatForever(sequence))
        firstTouch = firstTouchStorage
    }
    for touch in touches{
        if touch == firstTouch{
            touchesArray.append(touch)

            let angle = arrow.zRotation
            if touchesArray.count == 2{
                arrow.removeAllActions()
                arrow.removeFromParent()
            }
        }
    }

我试图解决这个问题太久了,但我无法弄清楚。我希望你能帮助我。

最佳答案

正如@KnightOfDragon 所建议的:animateWithTextures 有一个 restore: 参数,如果您将其设置为 false,当您停止动画时,最后一个纹理应该保留在 Sprite 上。如果您继续阅读纹理描述,那么您将知道它停止在什么纹理上,并可以相应地进行计划

关于ios - 如何跟踪 Sprite Kit 中的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42008897/

相关文章:

ios - 在 alamofire 响应后追加到现有数组

uiimagepickercontroller - 如何在 swift 中使用 UIImagePickerController 捕获相机?

ios - 通过segue将CollectionView的选定单元格索引发送到viewController

jquery - 如何添加动画来像微调器一样更改倒计时边框的颜色?

ios - 显示错误不可失败初始化程序 "init(coder:)"错误

iOS 用户权限

ios - Storyboard "show"segue 在更新到 xcode7 后不起作用(仅在一种情况下)

jquery动画循环问题

CSS3 动画 : Number Count Up?

iPhone 自定义 UI 设计和构建资源