Skip to main content

FlixelGamepadDevice

View source

class

org.flixelgdx.input.gamepad.FlixelGamepadDevice

public final class FlixelGamepadDevice

Optional per-slot facade for gamepad queries. Instances are created only when the game calls FlixelGamepadInputManager.ensureDevice(int); FlixelGamepadInputManager.getById(int) stays null until then.

Methods

getId()

public int getId()

Slot index for this device (stable while the controller stays at the same list index in the backend).

Returns: Gamepad id between 0 and FlixelGamepadInputManager.MAX_GAMEPADS exclusive.


isConnected()

public boolean isConnected()

Whether this slot currently maps to a connected controller.

Returns: true when connected.


getConnected()

public boolean getConnected()

Returns whether this gamepad slot currently maps to a connected controller.


getModel()

public FlixelGamepadModel getModel()

Model detected for this slot the last time the slot was (re)bound.

Returns: Detected model, or FlixelGamepadModel.UNKNOWN when out of range.


pressed(int)

public boolean pressed(int logicalButton)

Returns true when this controller is currently pressing the given button.

Parameters:

NameDescription
logicalButtonA logical button constant from FlixelGamepadButton.

Returns: true when the button is held this frame.


justPressed(int)

public boolean justPressed(int logicalButton)

Returns true when this controller first pressed the button this frame.

Parameters:

NameDescription
logicalButtonA logical button constant from FlixelGamepadButton.

Returns: true on the first frame the button is pressed.


justReleased(int)

public boolean justReleased(int logicalButton)

Returns true when this controller released the button this frame.

Parameters:

NameDescription
logicalButtonA logical button constant from FlixelGamepadButton.

Returns: true on the first frame the button is no longer pressed.


canVibrate()

public boolean canVibrate()

Returns whether this controller reports vibration support.

Returns: true when connected and the hardware supports vibration.


vibrate(float)

public void vibrate(float durationSecs)

Vibrates this controller at full intensity on both motors for the given duration.

Parameters:

NameDescription
durationSecsHow long to vibrate in seconds.

vibrate(float, float)

public void vibrate(float intensity, float durationSecs)

Vibrates this controller at the given intensity on both motors.

Parameters:

NameDescription
intensityMotor strength in the range [0, 1].
durationSecsHow long to vibrate in seconds.

vibrate(float, float, float)

public void vibrate(float leftIntensity, float rightIntensity, float durationSecs)

Vibrates this controller with independent left and right motor intensities.

Parameters:

NameDescription
leftIntensityStrength for the left (low-frequency) motor, in the range [0, 1].
rightIntensityStrength for the right (high-frequency) motor, in the range [0, 1].
durationSecsHow long to vibrate in seconds.

stopVibration()

public void stopVibration()

Stops any active vibration on this controller immediately.


getAxis(int)

public float getAxis(int logicalAxis)

Returns the current value of a logical axis on this controller, after dead-zone processing.

Parameters:

NameDescription
logicalAxisA logical axis constant from FlixelGamepadButton.

Returns: Axis value in the range [-1, 1], or 0f when inactive or within the dead zone.


getXAxis()

public float getXAxis()

Shorthand for the left stick horizontal axis (FlixelGamepadButton.AXIS_LEFT_X).

Returns: Horizontal axis value in the range [-1, 1].


getYAxis()

public float getYAxis()

Shorthand for the left stick vertical axis (FlixelGamepadButton.AXIS_LEFT_Y).

Returns: Vertical axis value in the range [-1, 1].


getTriggerL()

public float getTriggerL()

Analog pressure of the left trigger (L2), in the range [0, 1], after dead-zone processing.

On Jamepad/SDL desktop, triggers are axes; this reads the trigger axis directly. On web (TeaVM/W3C Gamepad API), triggers are digital buttons and this always returns 0; because of this, use FlixelGamepadDevice.pressed(int) with FlixelGamepadButton.L2 there instead.

Returns: Trigger pressure in [0, 1], or 0f within the dead zone.


getTriggerR()

public float getTriggerR()

Analog pressure of the right trigger (R2), in the range [0, 1], after dead-zone processing.

On Jamepad/SDL desktop, triggers are axes; this reads the trigger axis directly. On web (TeaVM/W3C Gamepad API), triggers are digital buttons and this always returns 0; because of this, use FlixelGamepadDevice.pressed(int) with FlixelGamepadButton.R2 there instead.

Returns: Trigger pressure in [0, 1], or 0f within the dead zone.