iOS Guides | Samples

MonoTouch.GameController Namespace

The GameController namespace provides support for external game controllers.


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 GCController.StartWirelessControllerDiscovery and will cause the GCController+Notifications.ObserveDidConnect notification handler to fire. When wireless controller disconnect, the GCController+Notifications.ObserveDidDisconnect notification fires.

There are two supported profiles for Game Controllers: GCGamepad and CGExtendedGamepad. A GCController will have a non-null value for either its CGController.Gamepad or its CGController.ExtendedGamepad property, the application developer must read those to determine the type.

CGGamepads have two shoulder buttons, a D-pad (see MonoTouch.GameController. GCControllerDirectionPad), and 4 face buttons labeled Y-B-A-X.

CGExtendedGamepads have the same elements, plus two trigger buttons and two joysticks (see 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:

PollingProperties such as GCControllerButtonInput.Pressed or GCControllerDirectionPad.XAxisDirectly read from the game-loop (see SKScene.Update).
Event-drivenElement's ValueChangedHandler property (such as 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 CGGamepad.SaveSnapshot, CGExtendedGamepad.SaveSnapshotSnapshots the controller state. Appropriate for marshalling, serialization, or delayed processing.

The major classes in the Game Controller namespace are shown in the following illustration:


GCControllerA game controller, either form-fitting or extended wireless.
GCController+NotificationsNotification posted by the GCController class.
GCControllerAxisInputA GCControllerElement representing a joystick.
GCControllerAxisValueChangedHandlerThe delegate used as the value-changed handler for GCControllerAxisInput.ValueChangedHandler.
GCControllerButtonInputA GCControllerElement representing a game-controller button.
GCControllerButtonValueChangedHandler that can be passed to the GCControllerButtonInput.SetPressedChangedHandler method to respond to changes to button states.
GCControllerDirectionPadA GCControllerElement representing a direction-pad.
GCControllerDirectionPadValueChangedHandlerThe delegate used as the value-changed handler for GCControllerDirectionPad.ValueChangedHandler.
GCControllerElementThe base class for input elements of a game controller.
GCControllerPlayerIndexEnumerates player controller indices.
GCEventViewControllerView controller that can switch event delivery between the responder chain and the game controller.
GCExtendedGamepadA gamepad with two shoulder buttons, two triggers, two thumbsticks, a D-Pad, and a directional button array.
GCExtendedGamepadSnapshotA serializable snapshot of the game controller's state.
GCExtendedGamepadSnapShotDataV100The state of a GCExtendedGamepad. Produced by GCExtendedGamepadSnapshot.TryGetSnapshotData.
GCExtendedGamepadValueChangedHandlerThe delegate used as the value-changed handler for GCExtendedGamepad.ValueChangedHandler.
GCGamepadA gamepad with two shoulder buttons, a D-Pad, and a directional button array..
GCGamepadSnapshotA serializable snapshot of the game controller's state.
GCGamepadSnapShotDataV100The state of a GCGamepad. Produced by GCGamepadSnapshot.TryGetSnapshotData.
GCGamepadValueChangedHandlerThe delegate used as the value-changed handler for GCGamepad.ValueChangedHandler.
GCMicroGamepadA logical mapping of hardware controller controls to a set of in-game elements.
GCMicroGamepadSnapshotGets snapshots of the state of a micro gamepad.
GCMicroGamepadSnapShotDataV100Represents the instantaneous state of a micro gamepad in V100 format at a point in time.
GCMicroGamepadValueChangedHandlerA handler that is called whenever any single element of a controller changes.
GCMotionHolds position data of a game controller.