我需要跟踪纹理动画。我正在设置电源条的动画,当用户点击屏幕时,它应该停止并节省电量。我无法弄清楚如何节省电力。到目前为止我有这个:在第一次触摸电源条动画,但在第二次触摸它只停止但不节省电力。
这是我创建动画的方式:
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()
}
}
}
我试图解决这个问题太久了,但我无法弄清楚。我希望你能帮助我。
答案 0 :(得分:0)
如@KnightOfDragon所建议:animateWithTextures具有restore:参数,如果将其设置为false,则在停止动画时,最后一个纹理应保留在精灵上。如果继续阅读纹理说明,那么您将知道它停止在什么纹理上,并可以据此计划