我给参数设置了一个函数,当给定某个字符串以引用要播放的下一个动画时,该函数可以运行多个动画。我的问题是,最先运行的动画将继续在所有其他假定动画的节点上运行,即使它们的动画完全不同。我想一旦完成,就需要用相应的键删除动画。
尝试执行这些操作,但似乎与我们设置SKAction的方式不兼容...
run(action: SKAction, completion: removeAnimation(animationAtlas: "\(animationAtlas)"))
func removeAnimation(animationAtlas: String) {
self.removeAction(forKey: "\(animationAtlas)")
}
这是我们的动画功能。
func animate(animationAtlas: String, runOnNode: SKSpriteNode, frameTime: Double) {
// need to remove animation after it is finished!!!!
let textureAtlas = SKTextureAtlas(named: "\(animationAtlas).atlas")
for i in 1...textureAtlas.textureNames.count {
let animationName = "\(animationAtlas)-\(i)"
animation.append(SKTexture(imageNamed: animationName))
animateAction = SKAction.animate(with: animation, timePerFrame: frameTime, resize: true, restore: false)
}
let animationToRun = runOnNode.run(SKAction.repeat((animateAction), count: 1), withKey: "\(animationAtlas)")
run(action: animationToRun, completion: removeAnimation(animationAtlas: "\(animationAtlas)"))
}
func removeAnimation(animationAtlas: String) {
self.removeAction(forKey: "\(animationAtlas)")
}
尝试执行这些操作,但是似乎与我们设置SKAction的方式不兼容。错误是我们在使用完成处理程序运行操作的地方。