我希望有人能够帮助我解决这个问题。我似乎找不到一种方法来为removeActionWithKey 方法的Sprite Kit 的SKAction 分配键。我还尝试将操作分配给字典中的键,但程序无法识别键分配,因此返回零值。
这是我尝试做的:
var textureanimation = SKAction.repeatActionForever(SKAction.animateWithTextures(_walkingframes, timePerFrame: 0.1))
var dictionary = ["animation": textureanimation]
object.runAction(actionForKey("animation"))
var sequence = [SKAction.moveTo(tap_position, duration: time_duration),
SKAction.runBlock{
object.removeActionForKey("animation")}
您可以在 runAction 方法中执行此操作
sprite.runAction(myCoolAction, withKey: "Cool Action")
这将允许您按名称删除操作
sprite.removeActionForKey("Cool Action")
根据经验,我建议将操作字符串名称放置在变量中。它将减少由于动作名称拼写轻微错误而产生的奇怪错误。
所以它的改进版本是 class var
let coolActionName = "Cool Action"
// Your other code
// Run the action
sprite.runAction(myCoolAction, withKey: coolActionName)
// Time to remove the action
sprite.removeActionForKey(coolActionName)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)