所以我在场景开始时加载并运行动画,但有一点我想停止动画。我确实理解为什么它不起作用,但我找不到解决它的方法。我尝试重写func update,但找不到更新函数的正确方法(如果有)。
override func didMove(to view: SKView) {
loadAnimation(atlasName: "test")
runAnimation(spriteName: "testImg", timeFrame: 0.08)
}
func loadAnimation(atlasName : String) {
let spriteAtlas = SKTextureAtlas(named: "\(atlasName)")
for index in 1...spriteAtlas.textureNames.count{
let image = String(format: "\(atlasName)%01d", index)
atlasAnimation += [spriteAtlas.textureNamed(image)]
}
}
func runAnimation(spriteName : String, timeFrame : Double) {
let spriteNode = self.childNode(withName: "\(spriteName)")
spriteNode?.name = "\(spriteName)"
if (spriteNode != nil) {
let animation = SKAction.animate(with: atlasAnimation, timePerFrame: timeFrame)
let forever = SKAction.repeatForever(animation)
spriteNode?.run(forever, withKey: "key")
if spriteNode?.name == "whatever" {
if i < 18 {
spriteNode?.removeAction(forKey: "key")
}
}
}