robreuss / VirtualGameController

Software-based game controllers for iOS, tvOS, OS X and watchOS in Swift 4.2.
MIT License
462 stars 44 forks source link

Connection question #29

Closed amckean closed 5 years ago

amckean commented 8 years ago

I am developing an Apple TV game that uses the iPhone/iPad as a game controller. I can discover the service, connect the two devices, but the VgcGameController.controllers() call on the iPhone always returns an empty array. How do I get ahold of the controller that is connected to the Apple TV (simulator)? BTW, the controllerDidConnect(notification) notification callback never gets called on the TV simulator, but it does get called on the iPhone.

Also, the only data that I want to send from the controller to the Apple TV is a CGPoint (or, if a CGPoint is not possible, an X/Y pair of Float or Int). Any ideas on the best strategy for this?

amckean commented 8 years ago

Revise the question above ... the iPhone shows up in the TV's controller.didConnect notification, along with an ExtendedGamePad (is this the simulator remote?). But VgcController.controllers() is always empty on the iPhone. How do I get a handle to the iPhone controller?

robreuss commented 8 years ago

You should be able to get a handle when didConnect fires, contained within the notification. Do something like this:

guard let newController: VgcController = notification.object as? VgcController else { vgcLogDebug("Got nil controller in controllerDidConnect") return }