OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 Sprite Kit 中跟踪动画 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:49
标题: ios - 如何在 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()
            }
        }
    }

我试图解决这个问题太久了,但我想不通。我希望你能帮助我。



Best Answer-推荐答案


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

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4