FlixelAnalogButtonReader
View sourceinterface
org.flixelgdx.input.gamepad.FlixelAnalogButtonReader
Platform bridge for reading the analog float value of a gamepad button.
The gdx-controllers Controller interface only exposes digital button state via getButton(int), which returns a boolean. On platforms such as web (W3C Gamepad API), trigger buttons carry an analog pressure value in [0, 1] that is otherwise inaccessible through the standard interface. Implementations of this interface read that value through platform-specific means.
The primary use case is populating FlixelGamepadButton.AXIS_TRIGGER_L and FlixelGamepadButton.AXIS_TRIGGER_R on backends where L2 and R2 are mapped to button indices (for example ControllerMapping.buttonL2 on web) rather than dedicated axes. Install a platform implementation via FlixelGamepadInputManager.setAnalogButtonReader(FlixelAnalogButtonReader).
On the Jamepad/SDL desktop backend, triggers are already reported as raw axes and no reader is needed. FlixelTeaVMAnalogButtonReader (in the flixelgdx-teavm module) covers the web case and is installed automatically by FlixelTeaVMLauncher.
See Also: FlixelGamepadInputManager.setAnalogButtonReader
Methods
read(Controller, int)
Returns the raw analog value of the button at nativeButtonIndex on the given controller, in the range [0, 1].
This is called from the per-frame polling loop, so the implementation must not allocate or block.
Parameters:
| Name | Description |
|---|---|
controller | The controller to read from. |
nativeButtonIndex | Raw button index (for example ControllerMapping.buttonL2). |
Returns: Analog value in the range [0, 1], or 0f when unavailable.