Skip to main content

FlixelAnalogBinding

View source

interface

org.flixelgdx.input.action.FlixelAnalogBinding

public interface 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)

public void accumulate(Vector2 out)

Adds this binding's contribution to out.

Parameters:

NameDescription
outAccumulator to modify in place.

negXKey(int)

public static FlixelAnalogBinding negXKey(int keycode)

Subtracts 1 from out.x while the key is held (left / negative X).

Parameters:

NameDescription
keycodelibGDX keycode.

Returns: Binding that contributes -1 on X when the key is pressed.


posXKey(int)

public static FlixelAnalogBinding posXKey(int keycode)

Adds 1 to out.x while the key is held (right / positive X).

Parameters:

NameDescription
keycodelibGDX keycode.

Returns: Binding that contributes +1 on X when the key is pressed.


negYKey(int)

public static FlixelAnalogBinding negYKey(int keycode)

Subtracts 1 from out.y while the key is held (down / negative Y).

Parameters:

NameDescription
keycodelibGDX keycode.

Returns: Binding that contributes -1 on Y when the key is pressed.


posYKey(int)

public static FlixelAnalogBinding posYKey(int keycode)

Adds 1 to out.y while the key is held (up / positive Y).

Parameters:

NameDescription
keycodelibGDX keycode.

Returns: Binding that contributes +1 on Y when the key is pressed.


gamepadAxisX(int, int)

public static FlixelAnalogBinding gamepadAxisX(int slot, int logicalAxis)

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:

NameDescription
slotGamepad slot (0 and up).
logicalAxisFlixelGamepadButton.AXIS_LEFT_X or similar.

Returns: Binding that contributes the stick X value.


gamepadAxisY(int, int)

public static FlixelAnalogBinding gamepadAxisY(int slot, int logicalAxis)

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:

NameDescription
slotGamepad slot (0 and up).
logicalAxisFlixelGamepadButton.AXIS_LEFT_Y or similar.

Returns: Binding that contributes the stick Y value (up = positive).


gamepadAxisY(int, int, boolean)

public static FlixelAnalogBinding gamepadAxisY(int slot, int logicalAxis, boolean raw)

Adds the Y component of a gamepad stick.

Parameters:

NameDescription
slotGamepad slot (0 and up).
logicalAxisFlixelGamepadButton.AXIS_LEFT_Y or similar.
rawWhen 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.