FlixelAnalogBinding
View sourceinterface
org.flixelgdx.input.action.FlixelAnalogBinding
Two-axis input contributor for a FlixelActionAnalog.
Each binding adds its contribution to a shared Vector2 accumulator each frame. Multiple bindings on the same action are summed, then normalized to a maximum length of 1 so diagonals do not exceed unit speed when mixing keys and sticks.
Create bindings only during setup, not each frame. The static factory methods cover the common cases (keyboard halves, gamepad axes). For anything else, pass a plain lambda:
move.addBinding("negX", FlixelAnalogBinding.negXKey(FlixelKey.A));
move.addBinding("posX", FlixelAnalogBinding.posXKey(FlixelKey.D));
move.addBinding("stickX", FlixelAnalogBinding.gamepadAxisX(0, FlixelGamepadButton.AXIS_LEFT_X));
move.addBinding("stickY", FlixelAnalogBinding.gamepadAxisY(0, FlixelGamepadButton.AXIS_LEFT_Y));
move.addBinding("custom", out -> out.x += myJoystick.getX());
Axis conventions
Key bindings contribute exactly -1 or +1 per axis. Gamepad axes contribute a smooth value in the range -1..1. FlixelAnalogBinding.gamepadAxisY(int, int) corrects the hardware Y axis (where up is negative in screen-space) so that up = positive Y, matching key bindings. Use gamepadAxisY(slot, axis, true) when you need the raw hardware value instead.
See Also: FlixelActionAnalog
Methods
accumulate(Vector2)
Adds this binding's contribution to out.
Parameters:
| Name | Description |
|---|---|
out | Accumulator to modify in place. |
negXKey(int)
Subtracts 1 from out.x while the key is held (left / negative X).
Parameters:
| Name | Description |
|---|---|
keycode | libGDX keycode. |
Returns: Binding that contributes -1 on X when the key is pressed.
posXKey(int)
Adds 1 to out.x while the key is held (right / positive X).
Parameters:
| Name | Description |
|---|---|
keycode | libGDX keycode. |
Returns: Binding that contributes +1 on X when the key is pressed.
negYKey(int)
Subtracts 1 from out.y while the key is held (down / negative Y).
Parameters:
| Name | Description |
|---|---|
keycode | libGDX keycode. |
Returns: Binding that contributes -1 on Y when the key is pressed.
posYKey(int)
Adds 1 to out.y while the key is held (up / positive Y).
Parameters:
| Name | Description |
|---|---|
keycode | libGDX keycode. |
Returns: Binding that contributes +1 on Y when the key is pressed.
gamepadAxisX(int, int)
Adds the X component of a gamepad stick. Most drivers report X in math-space already (left is negative, right is positive), so no correction is applied.
Parameters:
| Name | Description |
|---|---|
slot | Gamepad slot (0 and up). |
logicalAxis | FlixelGamepadButton.AXIS_LEFT_X or similar. |
Returns: Binding that contributes the stick X value.
gamepadAxisY(int, int)
Adds the Y component of a gamepad stick with the screen-space inversion corrected so that up = positive Y, matching key bindings. This is the right choice for almost every game.
Parameters:
| Name | Description |
|---|---|
slot | Gamepad slot (0 and up). |
logicalAxis | FlixelGamepadButton.AXIS_LEFT_Y or similar. |
Returns: Binding that contributes the stick Y value (up = positive).
gamepadAxisY(int, int, boolean)
Adds the Y component of a gamepad stick.
Parameters:
| Name | Description |
|---|---|
slot | Gamepad slot (0 and up). |
logicalAxis | FlixelGamepadButton.AXIS_LEFT_Y or similar. |
raw | When false (the default), the raw hardware Y is negated so that up = positive Y, matching key bindings. Pass true to use the raw screen-space value unchanged. |
Returns: Binding that contributes the stick Y value.