ios - How to repeat action as long I touch and when I stop touching the action stop in SpriteKit Swift -


as said in title want make action run , repeat long press button , stop , run action when stop touching. don't know method if me code example want sprite rotate long press , after stop touching move up.

let action = skaction.rotatebyangle(cgfloat(m_pi), duration:1.0)     sprite.runaction(skaction.repeatactionforever(action))             let action2 = skaction.movetoy(900, duration: 1.0)             sprite.runaction(action2) 

to describe want:

when touch screen object created , rotate , keep rotating till release finger screen , stop touching want go up

in sprite kit scene, these methods allow detect when touch begins , ends:

override func touchesbegan(touches: set<nsobject>, withevent event: uievent) {     // start action repeats indefinitely. }  override func touchesended(touches: set<nsobject>, withevent event: uievent) {     // remove action after touches end. } 

when touches end, call self.removeallactions() stop actions in scene, or sprite.removeallactions() stop actions specific sprite.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -