https://github.com/chaoscoder/appletvsimulatorcontroller
tvOS Simulator Game Controller
https://github.com/chaoscoder/appletvsimulatorcontroller
Last synced: about 1 year ago
JSON representation
tvOS Simulator Game Controller
- Host: GitHub
- URL: https://github.com/chaoscoder/appletvsimulatorcontroller
- Owner: ChaosCoder
- License: mit
- Created: 2015-10-31T08:53:19.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-31T09:16:11.000Z (over 10 years ago)
- Last Synced: 2025-02-17T10:30:38.759Z (over 1 year ago)
- Language: Swift
- Homepage:
- Size: 229 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Apple TV Simulator Game Controller
In tvOS the Apple TV remote can act as a game controller and is accessed through the Game Controller framework. As of Xcode 7.1 beta 2, though, the Game Controller framework is not supported in the Apple TV Simulator. This project provides a GCController implementation that will work with the simulator for testing. You can read more about its development at [Game Controller Support For Apple TV Simulator](http://iosdevstuff.blogspot.com/2015/10/game-controller-support-for-apple-tv.html).
## Usage
Add the files in the Controller directory to your project. GameViewController.swift provides an example of how to integrate it. The following sections describe each step.
### Conditionally create controller
```
#if arch(i386) || arch(x86_64)
scene.controller = createSimulatorController()
#else
NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleControllerDidConnectNotification:", name: GCControllerDidConnectNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleControllerDidDisconnectNotification:", name: GCControllerDidDisconnectNotification, object: nil)
#endif
```
### Register gesture recognizers
The controller depends on a few gesture recognizers that you'll need to add to your view.
```
func createSimulatorController() -> SimulatorController {
let controller = SimulatorController()
controller.createGestureRecognizers().forEach { view.addGestureRecognizer($0) }
return controller
}
```
### Forward touch events
You'll need to forward touch events to the controller.
```
#if arch(i386) || arch(x86_64)
override func pressesBegan(presses: Set, withEvent event: UIPressesEvent?) {
if let controller = scene?.controller as? SimulatorController {
controller.pressesBegan(presses, withEvent: event)
}
}
override func pressesChanged(presses: Set, withEvent event: UIPressesEvent?) {
}
override func pressesCancelled(presses: Set, withEvent event: UIPressesEvent?) {
if let controller = scene?.controller as? SimulatorController {
controller.pressesCancelled(presses, withEvent: event)
}
}
override func pressesEnded(presses: Set, withEvent event: UIPressesEvent?) {
if let controller = scene?.controller as? SimulatorController {
controller.pressesEnded(presses, withEvent: event)
}
}
#endif
```
## Caveats
This is a work around to allow limited Game Controller testing with the Apple TV simulator until Apple provides that functionality. It is not a compelete implementation of the Game Controller classes. A few things not implemented are:
* GCController.handlerQueue: all callbacks are delivered on the same thread that feeds keyboard events and gestures to the controller
* GCController.motion: returns nil
## License
AppleTVSimulatorController is available under the MIT license. See the LICENSE file for more info.