如何在Swift中为SKActions分配键
发布时间:2020-12-14 02:27:27 所属栏目:百科 来源:网络整理
导读:我希望有人能够帮我解决这个问题.我似乎找不到为removeActionWithKey方法为Sprite Kit分配SKAction的方法.我还尝试将操作分配给字典中的键,但程序无法识别键分配,因此返回了nil值. 这是我试图做的: var textureanimation = SKAction.repeatActionForever(SK
我希望有人能够帮我解决这个问题.我似乎找不到为removeActionWithKey方法为Sprite Kit分配SKAction的方法.我还尝试将操作分配给字典中的键,但程序无法识别键分配,因此返回了nil值.
这是我试图做的: 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") 根据经验,我建议在变量中放置动作字符串名称.它将减少来自非常轻微拼写错误的动作名称的奇怪错误. 所以这个改进版本是一个类var let coolActionName = "Cool Action" // Your other code // Run the action sprite.runAction(myCoolAction,withKey: coolActionName) // Time to remove the action sprite.removeActionForKey(coolActionName) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |