Search code examples
swiftsprite-kittvos

How to detect a remote click in SpriteKit and pass node information


I'm using Swift & SpriteKit.

I've got my sprite focused (using touches began and touches moved) & would like to click the remote to select it, but keep getting:

unrecognized selector sent to instance

Here's the code I'm using..

let tap = UITapGestureRecognizer(target: self, action: "processItemTouch")  
tap.allowedPressTypes = [NSNumber(integer: UIPressType.Select.rawValue)]  
view.addGestureRecognizer(tap)  

func processItemTouch(nod : SKNode) {
    // stuff to do
} 

I've tried changing the processItemTouch to processItemTouch: & processItemTouch(nod : SKNode).


Solution

  • Changing the selector to processItemTouch: should cause the right method to get called, but the argument that gets passed won't be an SKNode, it'll be a UITapGestureRecognizer. When gestures call their actions, the argument will be the gesture object that triggered the action.