ios - How to cancel one specific SKAction.movebyX in SpriteKit? -
i have skaction
want cancel in touchesended
. of right now, have code: self.player.removeallactions()
, code works. problem i'm experiencing code cancelling actions including animation of player. did research , found code: player.removeactionforkey()
, action code not include key. please see code below help. thank you.
import spritekit var player = skspritenode() //i skipped code in view did load. // in touches began: let rightmoveaction = skaction.movebyx(50, y: 0, duration: 0.1) player.runaction(skaction.repeatactionforever(rightmoveaction)) let leftmoveaction = skaction.movebyx(-50, y: 0, duration: 0.1) player.runaction(skaction.repeatactionforever(leftmoveaction)) // in touches ended self.player.removeallactions() // mentioned earlier, works need cancel 1 action not have animated player.
you can assign action key, , cancel referring key:
add key action:
player.runaction(skaction.repeatactionforever(rightmoveaction), withkey: "rightmove")
and remove doing this:
player.removeactionforkey("rightmove")
Comments
Post a Comment