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
Post a Comment