Bearbeiten

Freigeben über


GameController Namespace

The GameController namespace provides support for external game controllers.

Classes

GCController

A game controller, either form-fitting or extended wireless.

GCController.Notifications

Notification posted by the GCController class.

GCControllerAxisInput

A GCControllerElement representing a joystick.

GCControllerButtonInput

A GCControllerElement representing a game-controller button.

GCControllerDirectionPad

A GCControllerElement representing a direction-pad.

GCControllerElement

The base class for input elements of a game controller.

GCEventViewController

View controller that can switch event delivery between the responder chain and the game controller.

GCExtendedGamepad

A gamepad with two shoulder buttons, two triggers, two thumbsticks, a D-Pad, and a directional button array.

GCExtendedGamepadSnapshot

A serializable snapshot of the game controller's state.

GCGamepad

A gamepad with two shoulder buttons, a D-Pad, and a directional button array..

GCGamepadSnapshot

A serializable snapshot of the game controller's state.

GCMicroGamepad

A logical mapping of hardware controller controls to a set of in-game elements.

GCMicroGamepadSnapshot

Gets snapshots of the state of a micro gamepad.

GCMotion

Holds position data of a game controller.

Structs

GCExtendedGamepadSnapshotData
GCExtendedGamepadSnapShotDataV100

The state of a GCExtendedGamepad. Produced by TryGetSnapShotData(NSData, GCExtendedGamepadSnapShotDataV100).

GCGamepadSnapShotDataV100

The state of a GCGamepad. Produced by TryGetSnapshotData(NSData, GCGamepadSnapShotDataV100).

GCMicroGamepadSnapshotData
GCMicroGamepadSnapShotDataV100

Represents the instantaneous state of a micro gamepad in V100 format at a point in time.

Enums

GCControllerPlayerIndex

Enumerates player controller indices.

GCExtendedGamepadSnapshotDataVersion
GCMicroGamepadSnapshotDataVersion

Delegates

GCControllerAxisValueChangedHandler

The delegate used as the value-changed handler for ValueChangedHandler.

GCControllerButtonValueChanged

Handler that can be passed to the SetPressedChangedHandler(GCControllerButtonValueChanged) method to respond to changes to button states.

GCControllerDirectionPadValueChangedHandler

The delegate used as the value-changed handler for ValueChangedHandler.

GCExtendedGamepadValueChangedHandler

The delegate used as the value-changed handler for ValueChangedHandler.

GCGamepadValueChangedHandler

The delegate used as the value-changed handler for ValueChangedHandler.

GCMicroGamepadValueChangedHandler

A handler that is called whenever any single element of a controller changes.

Remarks

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

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

T:GameController.CGGamepad s have two shoulder buttons, a D-pad (see T:GameController. GCControllerDirectionPad), and 4 face buttons labeled Y-B-A-X.

T:GameController.CGExtendedGamepad s 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:

TechniqueMethod(s)Use
PollingProperties such as P:GameController.GCControllerButtonInput.Pressed or XAxisDirectly read from the game-loop (see Update).
Event-drivenElement's ValueChangedHandler property (such as M: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

M:GameController.CGGamepad.SaveSnapshot* , M: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: