Using Gestures with SpriteKit

Struggling with understanding the best approach for capturing gestures from the AppleTV default remote for a SpriteKit game. Please someone point me to a source example of best practices! What I have discovered so far is that utilizing touchesBegan touchesEnded on the SKScene doesn't work for interupreting gestures (if there is a proper way it is certanly nothing like how these methods behavior on touch screne devices).


It seems the recommended path is to capture gestures though UISwipeGestueRecognizer. Which I have tried


Inside


override func didMoveToView(view: SKView) {

...

let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: "swiped:")

swipeRecognizer.direction = .Right

view.addGestureRecognizer(swipeRecognizer)

}


//and of course the handler (not 100% sure this is correct as I am assumiing it is associated with the line above view.addGestureRecognizer(swipeR....)

@IBAction func swipeRecognizer(recognizer:UISwipeGestureRecognizer) {

print("got here code:001B")

}


It's been an extreemly frustrating experience working with the AppleTV OS dev kit with SpriteKit and most of that is around UI differences which are not documented and zero code examples exist. Apple should have provided more context sensitive examples. I would like to see very basic example exclusive to SpriteKit for how to properly capture gestures from the remote and all available buttons. I would pay for this example as at this point the user input captue has become the blocker for us.

What is the problem with your code? The general way to do this is to add a gesture recognizer to the view, which you are doing and have a function to handle the message....again which you have...so what is the issue?

If you have trouble with SpriteKit on the TV, you should check out their sample app DemoBots - https://developer.apple.com/go/?id=demobots-building-a-cross-platform-game-with-spritekit-and-gameplaykit


That answered lots of questions for me. Take a look at the GameControllerInputSource for how they are attaching listeners to the buttons. Note that they are using the GameController framework to manage that stuff. In my experience you can also just add the gesture recognizers to the skview and they work as advertised.


Hope that helps.


Kevin

Using the simulator or dev kit, when I make right guesture on the apple TV remote nothing happen. I never see "got here code:001B" printed to the debug console in XCode.

Thanks Kevin,


The later is what I'm looking for. I'd like an example of using gesture reconizers to identify all the buttons on the remote, etc... As stated implementing a gesture reconizer on my Scene is not working. The handler code never executes. It does when the same project is run on iOS touch devices.

Here is some code I'm using for debugging purposes. I'm attaching recognizers to the menu and play pause buttons to simulate a focus change left/right using my custom focus system for spritekit buttons.


let focusCycleRecognizer = UITapGestureRecognizer(target: self, action: "changeFocusRight")

focusCycleRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.PlayPause.rawValue)]

self.view.addGestureRecognizer(focusCycleRecognizer)


let focusCycleRecognizer1 = UITapGestureRecognizer(target: self, action: "changeFocusLeft")

focusCycleRecognizer1.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]

self.view.addGestureRecognizer(focusCycleRecognizer1)


Maybe that'll help.


Kevin

Using Gestures with SpriteKit
 
 
Q