FlixelDigitalBinding
View sourceinterface
org.flixelgdx.input.action.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
Pass to FlixelDigitalBinding.gamepadButton(int, int) so any active gamepad slot counts.
Methods
evaluate()
Returns true if this binding's input is active this frame.
Returns: true when the bound input is currently triggered.
key(int)
Keyboard key binding using Flixel.keys.
Parameters:
| Name | Description |
|---|---|
keycode | libGDX keycode (for example Keys.SPACE). |
Returns: Binding that fires while the key is held.
mouseButton(int)
Mouse button binding using Flixel.mouse.
Parameters:
| Name | Description |
|---|---|
button | Mouse button index (for example FlixelMouseButton.LEFT). |
Returns: Binding that fires while the button is held.
gamepadButton(int, int)
Gamepad button binding using Flixel.gamepads.
Parameters:
| Name | Description |
|---|---|
slot | Gamepad slot (0 and up), or FlixelDigitalBinding.GAMEPAD_SLOT_ANY to match any connected slot. |
logicalButton | Logical button value from FlixelGamepadButton. |
Returns: Binding that fires while the button is held on the given slot.
touch(int)
Touch pointer binding using Flixel.touches.
// Fire while the first finger is down.
shoot.addBinding("touch", FlixelDigitalBinding.touch(0));
Parameters:
| Name | Description |
|---|---|
pointer | Zero-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)
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:
| Name | Description |
|---|---|
normX | Left edge as a fraction of the back buffer width (0..1). |
normY | Top edge as a fraction of the back buffer height (0..1). |
normW | Width as a fraction of the back buffer width (0..1). |
normH | Height 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)
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:
| Name | Description |
|---|---|
x | Left edge in world units. |
y | Bottom edge in world units. |
w | Width in world units. |
h | Height in world units. |
Returns: Binding that fires while any touch pointer's world position is inside the region.