How to assign Keys to SKActions in Swift

谁说胖子不能爱 提交于 2019-12-04 08:50:33

You can do it in the runAction method

sprite.runAction(myCoolAction, withKey: "Cool Action")

This will allow you to remove the action by name

sprite.removeActionForKey("Cool Action")

Just from experience, I'd recommend placing action string names in variables. It will cut down on the weird bugs from very slightly misspelled action names.

So an improved version of this is a 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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!