gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:15:11 25 4
gpt4 key购买 nike

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

这是我创建动画的方式:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com