GCController
A representation of a real game controller, a virtual controller, or a snapshot of a controller.
Declaration
class GCControllerMentioned in
Overview
This class represents a real or virtual controller that a user interacts with during a game. A real controller is a physical controller that connects directly or wirelessly to the device. A real controller can be formfitting or can attach closely to a device so players can use controls on both simultaneously. A virtual controller is a software emulation of a real controller.
You discover controllers, and then you process the input from those controllers during gameplay. Use the controllers() method to get the currently connected controllers. If necessary, use the startWirelessControllerDiscovery(completionHandler:) method to connect with wireless controllers.
This framework supports multiple connected game controllers. To identify which player is using a controller in a multiplayer game, check the playerIndex property and set it, if necessary. For single-player games, use the current property to get the controller that the player is actively using.
A controller’s profile encapsulates the details about a controller’s buttons, pads, axis, and other input elements. Get the controller’s profile using one of the profile properties, such as extendedGamepad, and then process the input from its elements.
You can either get the values of input elements on each iteration of your game loop, or set handlers to receive callbacks when those values change. For example, use the leftThumbstick property of the GCExtendedGamepad profile to get the thumbstick state. Use the valueChangedHandler property to set a handler that you implement to process any input values that change in the profile.
Alternatively, you can create a snapshot of a real or virtual controller using the capture() method. A snapshot is a copy of a controller at a moment in time with its current element values. Creating a snapshot may impact performance, and over time a snapshot doesn’t stay current. Unlike other types of controllers, you can set the values of elements in a snapshot.
Topics
Discovering controllers
controllers()startWirelessControllerDiscovery(completionHandler:)stopWirelessControllerDiscovery()GCControllerDidConnectGCControllerDidDisconnect
Handling multiple controllers
Inspecting a controller
Accessing controller input
Accessing controller profiles
extendedGamepadGCPhysicalInputProfileGCKeyboardInputGCMouseInputGCExtendedGamepadGCDualShockGamepadGCXboxGamepadGCDualSenseGamepadmicroGamepadGCMicroGamepadGCDirectionalGamepadmotionphysicalInputProfilegamepad
Accessing controller elements
GCControllerElementGCControllerAxisInputGCControllerButtonInputGCControllerTouchpadGCControllerDirectionPadGCDeviceCursorGCDualSenseAdaptiveTrigger