Skip to main content

FlixelDigitalBinding

View source

interface

org.flixelgdx.input.action.FlixelDigitalBinding

public interface FlixelDigitalBinding

Boolean input contributor for a FlixelActionDigital.

Each binding answers one question per frame: is this input active right now? Multiple bindings added to the same action are OR'd together, so the action fires if any one of them returns true.

Create bindings only during setup, not each frame. The static factory methods cover the common cases (keyboard, mouse, gamepad, touch region). For anything else, pass a plain lambda:

jump.addBinding("keyboard", FlixelDigitalBinding.key(FlixelKey.SPACE));
jump.addBinding("gamepad", FlixelDigitalBinding.gamepadButton(0, FlixelGamepadButton.A));
jump.addBinding("touch", FlixelDigitalBinding.touch(0));
jump.addBinding("sensor", () -> myCustomSensor.isActive());

See Also: FlixelActionDigital

Fields

GAMEPAD_SLOT_ANY

public static final int GAMEPAD_SLOT_ANY = -1

Pass to FlixelDigitalBinding.gamepadButton(int, int) so any active gamepad slot counts.


Methods

evaluate()

public boolean evaluate()

Returns true if this binding's input is active this frame.

Returns: true when the bound input is currently triggered.


key(int)

public static FlixelDigitalBinding key(int keycode)

Keyboard key binding using Flixel.keys.

Parameters:

NameDescription
keycodelibGDX keycode (for example Keys.SPACE).

Returns: Binding that fires while the key is held.


mouseButton(int)

public static FlixelDigitalBinding mouseButton(int button)

Mouse button binding using Flixel.mouse.

Parameters:

NameDescription
buttonMouse button index (for example FlixelMouseButton.LEFT).

Returns: Binding that fires while the button is held.


gamepadButton(int, int)

public static FlixelDigitalBinding gamepadButton(int slot, int logicalButton)

Gamepad button binding using Flixel.gamepads.

Parameters:

NameDescription
slotGamepad slot (0 and up), or FlixelDigitalBinding.GAMEPAD_SLOT_ANY to match any connected slot.
logicalButtonLogical button value from FlixelGamepadButton.

Returns: Binding that fires while the button is held on the given slot.


touch(int)

public static FlixelDigitalBinding touch(int pointer)

Touch pointer binding using Flixel.touches.

// Fire while the first finger is down.
shoot.addBinding("touch", FlixelDigitalBinding.touch(0));

Parameters:

NameDescription
pointerZero-based pointer index (0 = first finger).

Returns: Binding that fires while the given pointer is in contact with the screen.


touchRegion(float, float, float, float)

public static FlixelDigitalBinding touchRegion(float normX, float normY, float normW, float normH)

Normalized screen region binding. Fires when any active touch pointer falls inside the rectangle. Coordinates are fractions of the back buffer dimensions, with the origin at the top-left corner (matching libGDX screen-space Y, where Y increases downward).

// Bottom-left quarter of the screen as a virtual jump button.
jump.addBinding("touch", FlixelDigitalBinding.touchRegion(0f, 0.5f, 0.5f, 0.5f));

Parameters:

NameDescription
normXLeft edge as a fraction of the back buffer width (0..1).
normYTop edge as a fraction of the back buffer height (0..1).
normWWidth as a fraction of the back buffer width (0..1).
normHHeight as a fraction of the back buffer height (0..1).

Returns: Binding that fires while any touch pointer is inside the region.


touchRegionWorld(float, float, float, float)

public static FlixelDigitalBinding touchRegionWorld(float x, float y, float w, float h)

World-space region binding. Fires when any active touch pointer's unprojected world position falls inside the rectangle. Coordinates use the bottom-left origin (Y increases upward), matching the standard game-world convention used by cameras and game objects.

World coordinates are taken from FlixelTouch.worldX and FlixelTouch.worldY, which are unprojected each frame via the touch manager's active camera (configurable with FlixelTouchManager.setWorldCamera(...)).

// Virtual jump button occupying the left half of a 480x270 world.
jump.addBinding("touch", FlixelDigitalBinding.touchRegionWorld(0f, 0f, 240f, 270f));

Parameters:

NameDescription
xLeft edge in world units.
yBottom edge in world units.
wWidth in world units.
hHeight in world units.

Returns: Binding that fires while any touch pointer's world position is inside the region.