xcode - SKSpriteNode drag movement by touch -



xcode - SKSpriteNode drag movement by touch -

i'm trying drag skspirtenode around screen touching screen. want able constant motion of sprite, code moves sprite location of touch if hold , move sprite not follow. don't want "have" touch skspritenode activate movement, want touch anywhere on screen , have motion response skspritenode.

here current code:

class gamescene: skscene { override func didmovetoview(view: skview) { // spritenode want drag around basket = skspritenode(texture: baskettexture) self.addchild(basket) } override func touchesbegan(touches: nsset, withevent event: uievent) { /* called when touch begins */ var nodetouched = sknode() var currentnodetouched = sknode() touch: anyobject in touches { allow location = touch.locationinnode(self) nodetouched = self.nodeatpoint(location) basket.position = location }

thank help appreciated.

i solved using func touchesmoved instead of touchesbegan , works , smoothly. here final code:

class gamescene: skscene { override func didmovetoview(view: skview) { // spritenode want drag around basket = skspritenode(texture: baskettexture) self.addchild(basket) } override func touchesmoved(touches: nsset, withevent event: uievent) { /* called when touch begins */ var nodetouched = sknode() var currentnodetouched = sknode() touch: anyobject in touches { allow location = touch.locationinnode(self) nodetouched = self.nodeatpoint(location) basket.position = location }

xcode swift ios8 sprite-kit

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -