SdlGamepad class
A gamepad that is connected to the host device.
To open a gamepad:
- Use SdlGamepad.fromGamepadIndex with a gamepad ID
- Use SdlGamepad.fromPlayerIndex with a player ID
- Check getConnectedGamepadIds and use one with SdlGamepad.fromGamepadIndex
Before using any gamepad, be sure to call SdlLibrary.init. Otherwise, inputs may not register.
Once a gamepad is connected, it can be disconnected at any time. Always check isConnected to have the latest info. The current state of the gamepad (which buttons are pressed) can be queried at any time using getState. Once done with the gamepad, remember to call close.
The gamepad ID and player ID are two distinct concepts which are explained in detail in SdlGamepad.fromGamepadIndex and SdlGamepad.fromPlayerIndex, but to summarize, a gamepad ID is assigned when a gamepad is connected and does not change until the gamepad is disconnected. A player ID is a unique ID per human user and represents the n-th input device.
- Available extensions
Constructors
- SdlGamepad.fromGamepadIndex(int index)
- Opens a gamepad of the given index.
- SdlGamepad.fromPlayerIndex(int index)
- Opens a gamepad assigned to the given player index.
-
SdlGamepad.fromPointer(Pointer<
SdlGamepad> sdlGamepad) - Re-uses an already-opened SDL3 gamepad pointer.
Properties
- battery → int?
-
Available on SdlGamepad, provided by the GamepadPower extension
The current battery level of the gamepad, as a percentage (0 - 100).no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- id → int?
-
Gets the gamepad ID of the gamepad. See SdlGamepad.fromGamepadIndex for details.
no setter
- isConnected → bool
-
Whether this gamepad is connected.
no setter
- playerIndex → int?
-
Gets the player ID of the gamepad. See SdlGamepad.fromPlayerIndex for details.
no setter
- powerState → GamepadPowerState
-
Available on SdlGamepad, provided by the GamepadPower extension
Gets the current power state of the gamepad.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
sdlGamepad
→ Pointer<
SdlGamepad> -
A pointer to the gamepad object managed by SDL.
final
Methods
-
close(
) → void - Closes the gamepad and releases any resources used by this object.
-
getConnectionState(
) → GamepadConnectionState - Gets the state of this gamepad's connection (how it's connected).
-
getInfo(
) → GamepadInfo - Gets associated info about the gamepad and its physical configuration.
-
getState(
) → GamepadState - Gets the current state of the gamepad and all the buttons that are pressed.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rumble(
{required Duration duration, double intensity = 1}) → void -
Available on SdlGamepad, provided by the GamepadRumble extension
Rumbles the gamepad at the given intensity. -
rumbleSides(
{required Duration duration, double leftIntensity = 1, double rightIntensity = 1}) → void -
Available on SdlGamepad, provided by the GamepadRumble extension
Rumbles each side of the gamepad at the given intensity. -
rumbleTriggers(
{required Duration duration, double leftIntensity = 1, double rightIntensity = 1}) → bool -
Available on SdlGamepad, provided by the GamepadRumble extension
Rumbles the triggers at the given intensity. -
stopRumble(
) → void -
Available on SdlGamepad, provided by the GamepadRumble extension
Stops rumbling. Equivalent to calling rumble with zero intensity. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
getConnectedGamepadIds(
) → List< int> - Gets a list of gamepad IDs for all currently connected gamepads.
-
getInfoForGamepadId(
int gamepadId) → GamepadInfo - Gets associated info about the gamepad and its physical configuration.