FlixelGamepadInputManager
View sourceclass
org.flixelgdx.input.gamepad.FlixelGamepadInputManager
Global gamepad manager backed by gdx-controllers. Polls controllers each frame and mirrors the keyboard and mouse frame contract from FlixelGame.
The gamepad system is disabled by default. Set FlixelGamepadInputManager.enabled to true before the game loop starts to opt in:
Flixel.gamepads.enabled = true;
Use logical button and axis constants from FlixelGamepadButton (for example FlixelGamepadButton.A) with FlixelGamepadInputManager.pressed(int, int); each Controller.getMapping() supplies native indices. FlixelGamepadDevice is optional; call FlixelGamepadInputManager.ensureDevice(int) once per slot you want a facade for.
Constructors
FlixelGamepadInputManager()
Fields
MAX_GAMEPADS
Maximum supported simultaneous controllers.
numActiveGamepads
Number of controllers mapped to IDs 0 .. numActiveGamepads-1 this frame.
globalDeadZone
Optional analog dead zone applied to all axis reads when non-null. When null, only exact zeroing for true zero input is skipped.
deviceConnected
deviceDisconnected
enabled
Whether the gamepad system is active. When false, all queries return inactive state and no hardware is polled. Defaults to false; set to true to opt in before the game loop starts.
Methods
attach()
Registers a ControllerListener with gdx-controllers. Safe to call more than once.
detach()
Unregisters listeners and clears internal slot state.
reset()
update()
endFrame()
getById(int)
Returns the cached FlixelGamepadDevice for a slot if the game previously called FlixelGamepadInputManager.ensureDevice(int).
Parameters:
| Name | Description |
|---|---|
id | Slot id. |
Returns: Cached device, or null.
ensureDevice(int)
Ensures a FlixelGamepadDevice exists for the given slot. At most one instance is created per id for the lifetime of this manager (until FlixelGamepadInputManager.reset()).
Parameters:
| Name | Description |
|---|---|
id | Slot id. |
Returns: Non-null device facade.
getFirstActiveGamepadId()
First slot with any button beyond dead zone or analog movement this frame, or -1.
Returns: Active id, or -1 when none.
getFirstActiveGamepad()
Returns a device for FlixelGamepadInputManager.getFirstActiveGamepadId() only when that slot was already ensured.
Returns: Device, or null.
getActiveGamepadIds(int[])
Writes active slot ids in order to reuseOut[0 .. count-1].
Parameters:
| Name | Description |
|---|---|
reuseOut | Caller buffer; length should be at least FlixelGamepadInputManager.MAX_GAMEPADS. |
Returns: Number of ids written.
getActiveGamepads(FlixelGamepadDevice[])
Fills reuseOut with FlixelGamepadDevice instances that were previously ensured and are still connected.
Parameters:
| Name | Description |
|---|---|
reuseOut | Caller buffer. |
Returns: Number of entries written.
anyPressed(int)
Returns true when any active gamepad currently holds the given button.
Parameters:
| Name | Description |
|---|---|
logicalButton | A logical button constant from FlixelGamepadButton, such as FlixelGamepadButton.A. |
Returns: true when at least one gamepad is pressing the button this frame.
anyJustPressed(int)
Returns true when any active gamepad first pressed the given button this frame.
Parameters:
| Name | Description |
|---|---|
logicalButton | A logical button constant from FlixelGamepadButton. |
Returns: true when at least one gamepad transitioned to pressed this frame.
anyJustReleased(int)
Returns true when any active gamepad released the given button this frame.
Parameters:
| Name | Description |
|---|---|
logicalButton | A logical button constant from FlixelGamepadButton. |
Returns: true when at least one gamepad transitioned to released this frame.
anyInput()
Returns true when any active gamepad has a button pressed or an analog input beyond the dead zone this frame.
Returns: true when at least one gamepad is producing input.
anyMovedXAxis()
Returns true when any active gamepad is moving a left or right stick horizontally beyond the dead zone this frame.
Returns: true when at least one gamepad has horizontal stick movement.
anyMovedYAxis()
Returns true when any active gamepad is moving a left or right stick vertically beyond the dead zone this frame.
Returns: true when at least one gamepad has vertical stick movement.
pressed(int, int)
Returns true when the given slot is currently pressing the given button.
Pass FlixelGamepadButton.ANY as the button to check whether the slot has any button pressed or meaningful analog movement this frame.
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
logicalButton | A logical button constant from FlixelGamepadButton. |
Returns: true when that button is pressed on the given slot this frame.
justPressed(int, int)
Returns true when the given slot first pressed the button this frame (was not pressed last frame).
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
logicalButton | A logical button constant from FlixelGamepadButton. |
Returns: true on the first frame the button is pressed.
justReleased(int, int)
Returns true when the given slot released the button this frame (was pressed last frame, not pressed now).
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
logicalButton | A logical button constant from FlixelGamepadButton. |
Returns: true on the first frame the button is no longer pressed.
firstPressed(int)
Returns the logical button code of the button that has been held the longest on the given slot, or FlixelGamepadButton.NONE when no button is currently held.
Press order is tracked across frames: the first physical button detected as pressed since the slot was connected (or last cleared) is always returned first, regardless of how many buttons are held simultaneously.
int btn = Flixel.gamepads.firstPressed(0);
if (btn != FlixelGamepadButton.NONE) {
System.out.println("Oldest held button: " + FlixelGamepadButton.toString(btn));
}
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
Returns: Logical button code from FlixelGamepadButton, or FlixelGamepadButton.NONE when no button is held or the slot is inactive.
firstJustPressed(int)
Returns the logical button code of the first button that transitioned to pressed this frame on the given slot, or FlixelGamepadButton.NONE when no button was just pressed.
When multiple buttons are pressed in the same frame, the one with the lowest native index is returned. Unmapped native buttons (those not in FlixelGamepadButton) are skipped.
int btn = Flixel.gamepads.firstJustPressed(0);
if (btn == FlixelGamepadButton.A) {
jump();
}
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
Returns: Logical button code from FlixelGamepadButton, or FlixelGamepadButton.NONE when no button was just pressed or the slot is inactive.
firstJustReleased(int)
Returns the logical button code of the first button that was released this frame on the given slot, or FlixelGamepadButton.NONE when no button was just released.
When multiple buttons are released in the same frame, the one with the lowest native index is returned. Unmapped native buttons (those not in FlixelGamepadButton) are skipped.
int btn = Flixel.gamepads.firstJustReleased(0);
if (btn == FlixelGamepadButton.A) {
stopCharge();
}
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
Returns: Logical button code from FlixelGamepadButton, or FlixelGamepadButton.NONE when no button was just released or the slot is inactive.
getAxis(int, int)
Returns the current value of a logical axis on the given slot, after applying the global dead zone. Returns 0f when the value is within the dead zone or the slot is out of range.
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
logicalAxis | A logical axis constant from FlixelGamepadButton, such as FlixelGamepadButton.AXIS_LEFT_X. |
Returns: Axis value in the range [-1, 1], or 0f when inactive.
getModel(int)
Model detected for the given slot the last time the slot was (re)bound.
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
Returns: Detected model, or FlixelGamepadModel.UNKNOWN when out of range or unrecognized.
setHapticsProvider(FlixelHapticsProvider)
Replaces the haptics backend used by all vibration calls on this manager.
Each platform launcher installs a provider automatically: FlixelLwjgl3Launcher installs FlixelLwjgl3HapticsProvider (Jamepad/SDL, true dual-motor), and FlixelTeaVMLauncher installs FlixelTeaVMHapticsProvider (W3C Gamepad Haptics API, true dual-motor). Only override this when you need platform-specific features that the built-in providers do not cover, such as DualSense adaptive triggers or haptic patterns.
Parameters:
| Name | Description |
|---|---|
provider | Non-null replacement provider. |
Throws:
| Type | Description |
|---|---|
NullPointerException | If provider is null. |
setAnalogButtonReader(FlixelAnalogButtonReader)
Installs a platform-specific reader for analog button values, used to populate FlixelGamepadButton.AXIS_TRIGGER_L and FlixelGamepadButton.AXIS_TRIGGER_R on backends where triggers are exposed as buttons rather than axes (for example, the web W3C Gamepad API).
FlixelTeaVMAnalogButtonReader (installed automatically by FlixelTeaVMLauncher) is the only built-in implementation. Pass null to disable analog button reading and fall back to the axis-only trigger behavior.
Parameters:
| Name | Description |
|---|---|
reader | Reader to install, or null to clear any existing reader. |
canVibrate(int)
Returns whether the controller in the given slot reports vibration support.
Parameters:
| Name | Description |
|---|---|
slot | Slot index. |
Returns: true when the system is enabled, the slot is in range, and the hardware reports haptics capability.
vibrate(int, float)
Vibrates the controller in the given slot at full intensity on both motors for the given duration.
// Short full-strength rumble on the first controller.
Flixel.gamepads.vibrate(0, 0.3f);
Parameters:
| Name | Description |
|---|---|
slot | Slot index. |
durationSecs | How long to vibrate in seconds. |
vibrate(int, float, float)
Vibrates the controller in the given slot at the given intensity on both motors.
Parameters:
| Name | Description |
|---|---|
slot | Slot index. |
intensity | Motor strength in the range [0, 1]. |
durationSecs | How long to vibrate in seconds. |
vibrate(int, float, float, float)
Vibrates the controller in the given slot with independent left and right motor intensities.
// Rumble only the left (low-frequency) motor at half strength for half a second.
Flixel.gamepads.vibrate(0, 0.5f, 0f, 0.5f);
Parameters:
| Name | Description |
|---|---|
slot | Slot index. |
leftIntensity | Strength for the left (low-frequency) motor, in the range [0, 1]. |
rightIntensity | Strength for the right (high-frequency) motor, in the range [0, 1]. |
durationSecs | How long to vibrate in seconds. |
getTriggerL(int)
Returns the current analog pressure of the left trigger (L2) on the given slot, in the range [0, 1], after applying the global dead zone.
On the Jamepad/SDL desktop backend, triggers are reported as axes, so this reads the raw trigger axis directly. On web (TeaVM/W3C Gamepad API), triggers are digital buttons; this method returns 0 there; for web, use FlixelGamepadInputManager.pressed(int, int) with FlixelGamepadButton.L2 instead.
float howHardL2 = Flixel.gamepads.getTriggerL(0);
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
Returns: Trigger pressure in [0, 1], or 0f when inactive or within the dead zone.
getTriggerR(int)
Returns the current analog pressure of the right trigger (R2) on the given slot, in the range [0, 1], after applying the global dead zone.
On the Jamepad/SDL desktop backend, triggers are reported as axes, so this reads the raw trigger axis directly. On web (TeaVM/W3C Gamepad API), triggers are digital buttons; this method returns 0 there; for web, use FlixelGamepadInputManager.pressed(int, int) with FlixelGamepadButton.R2 instead.
float howHardR2 = Flixel.gamepads.getTriggerR(0);
Parameters:
| Name | Description |
|---|---|
gamepadId | Slot index. |
Returns: Trigger pressure in [0, 1], or 0f when inactive or within the dead zone.
stopVibration(int)
Stops any active vibration on the controller in the given slot immediately.
Parameters:
| Name | Description |
|---|---|
slot | Slot index. |
controllerAt(int)
Returns the raw, underlying gdx-controllers Controller object at the given index.
Parameters:
| Name | Description |
|---|---|
slot | Slot index. |
Returns: The gdx-controllers Controller object from the provided index, or null if it could not be found.
connected(Controller)
disconnected(Controller)
buttonDown(Controller, int)
buttonUp(Controller, int)
axisMoved(Controller, int, float)
GamepadConnectedEvent
class
org.flixelgdx.input.gamepad.FlixelGamepadInputManager.GamepadConnectedEvent
Mutable payload reused for FlixelGamepadInputManager.deviceConnected; do not retain past the callback.
Constructors
GamepadConnectedEvent()
Methods
gamepadId()
model()
GamepadDisconnectedEvent
class
org.flixelgdx.input.gamepad.FlixelGamepadInputManager.GamepadDisconnectedEvent
Mutable payload reused for FlixelGamepadInputManager.deviceDisconnected; do not retain past the callback.