GCMicroGamepad and Apple TV Remote

I'm looking to port an old mac game of mine to Apple TV. I need a dpad and a button. Do I only need to implement GCMicroGamepad to support the Apple TV Remote? There's no definate answer in the documentation. All I know is, "Game Controllers are not working with the simulator in this beta."


If I add support for this gamepad. Will I get my dpad and button support without having to implement any gesture recognizers?

Answered by jacksonjude in 58267022

You first have to run: GCController.startWirelessControllerDiscoveryWithCompletionHandler.

Then, setup: NSNotificationCenter.defaultCenter().addObserverForName(GCControllerDidConnectNotification, object: nil, queue: nil) { note in }

Inside the brackets, set your controller value to: GCController.controllers().first!

You can then access it at: controller.microGamepad


Furthermore, to access dpad values, create the following in the completion handler:

controller.microGamepad?.valueChangedHandler = { (gamepad, element) -> Void in
     if element == controller.microGamepad?.dpad {
          if controller.microGamepad?.dpad.left.value > 0.0 {
               //Use your dpad.left.value code here
          }
     }
}


Jackson

Hi BinaryBeard,


I have been looking into this as well over the last few days. There (obviously) isn't a whole lot that I can find as of yet, but from this document from the Apple docs, it seems that games on tvOS must support the GCMicroGamepad at the very least. It appears to me as though supporting all controllers is optional, although honestly it is a bit difficult to interpret from those guidelines.


With that said, I would take a look at the DemoBots GameControllerInputSource implementation. It supports everything, and you could probably trim it down quite a bit in your project to support tvOS specific input.


Doesn't totally answer your question but hopefully it helps! Keep us posted on your progress and discoveries.


Mark

Accepted Answer

You first have to run: GCController.startWirelessControllerDiscoveryWithCompletionHandler.

Then, setup: NSNotificationCenter.defaultCenter().addObserverForName(GCControllerDidConnectNotification, object: nil, queue: nil) { note in }

Inside the brackets, set your controller value to: GCController.controllers().first!

You can then access it at: controller.microGamepad


Furthermore, to access dpad values, create the following in the completion handler:

controller.microGamepad?.valueChangedHandler = { (gamepad, element) -> Void in
     if element == controller.microGamepad?.dpad {
          if controller.microGamepad?.dpad.left.value > 0.0 {
               //Use your dpad.left.value code here
          }
     }
}


Jackson

GCMicroGamepad and Apple TV Remote
 
 
Q