The Game Controller namespace was added in iOS 7 and adds support for game controllers.
Game controllers come in two forms: "form-fitting" controllers that contain an iOS device and "extended wireless" controllers that wirelessly connect to an iOS device or a Mac.
Game controllers must be optional components: game developers must make their game playable by users who do not have game controllers.
Form-fitting controllers are automatically discovered by the system. Extended wireless controllers are discovered by the system subsequent to the application developer calling MonoTouch.GameController.GCController.StartWirelessControllerDiscovery and will cause the MonoTouch.GameController.GCController.Notifications.ObserveDidConnect notification handler to fire. When wireless controller disconnect, the MonoTouch.GameController.GCController.Notifications.ObserveDidDisconnect notification fires.
There are two supported profiles for Game Controllers: MonoTouch.GameController.GCGamepad and MonoTouch.GameController.CGExtendedGamepad. A MonoTouch.GameController.GCController will have a non-null value for either its MonoTouch.GameController.CGController.Gamepad or its MonoTouch.GameController.CGController.ExtendedGamepad property, the application developer must read those to determine the type.
MonoTouch.GameController.CGGamepads have two shoulder buttons, a D-pad (see MonoTouch.GameController. GCControllerDirectionPad), and 4 face buttons labeled Y-B-A-X.
MonoTouch.GameController.CGExtendedGamepads have the same elements, plus two trigger buttons and two joysticks (see MonoTouch.GameController.GCControllerAxisInput). Apple conceptual schematics additionally show an LED array, but there is currently no programmatic access to this element.
There are three ways to read game controller data:
| Technique | Method(s) | Use |
|---|---|---|
| Polling | Properties such as MonoTouch.GameController.GCControllerButtonInput.Pressed or MonoTouch.GameController.GCControllerDirectionPad.XAxis | Directly read from the game-loop (see MonoTouch.SpriteKit.SKScene.Update). |
| Event-driven | Element's ValueChangedHandler property (such as MonoTouch.GameController.GControllerButtonInput.ValueChangedHandler) | Game Controller processes updates on the main thread. The framework ensures that simultaneously-occurring events result in a series of single callbacks. |
| Coordinated Snapshot | MonoTouch.GameController.CGGamepad.SaveSnapshot, MonoTouch.GameController.CGExtendedGamepad.SaveSnapshot | Snapshots the controller state. Appropriate for marshalling, serialization, or delayed processing. |
The major classes in the Game Controller namespace are shown in the following illustration:
