Skip to main content

FlixelActionSet

View source

class

org.flixelgdx.input.action.FlixelActionSet

public class FlixelActionSet implements FlixelUpdatable, FlixelDestroyable

Groups logical FlixelAction instances (digital and analog) and advances them on the same frame contract as FlixelInputManager. Actions read Flixel.keys, Flixel.mouse, Flixel.gamepads, and Gdx.input during FlixelActionSet.update(float). This class is not an InputProcessor: you do not add it to InputMultiplexer. Framework keyboard and mouse processors stay the single libGDX entry points for those devices.

Lifecycle (normal games)

Example Usage

public class PlayerControls extends FlixelActionSet {

public final FlixelActionDigital jump;
public final FlixelActionAnalog move;

public PlayerControls() {
jump = new FlixelActionDigital("jump");
jump.addBinding("keyboard", FlixelDigitalBinding.key(FlixelKey.SPACE));
jump.addBinding("gamepad", FlixelDigitalBinding.gamepadButton(0, FlixelGamepadButton.A));
add(jump);

move = new FlixelActionAnalog("move");
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));
add(move);
}
}

Then, in a state for your game:

public class PlayState extends FlixelState {

private final PlayerControls controls = new PlayerControls();

@Override
public void update(float elapsed) {
if (controls.jump.justPressed()) {
// Fire jump once this frame.
}
float mx = controls.move.getX();
float my = controls.move.getY();
}

@Override
public void destroy() {
controls.destroy();
super.destroy();
}
}

Steam Input

Set FlixelActionSet.steamReader to an implementation that reads Steam Input API (for example via steamworks4j). Action FlixelAction.getName() strings should match your in-game actions manifest. Use FlixelSteamActionReaders.EMPTY when Steam is unavailable.

Tests

Pass false to FlixelActionSet.FlixelActionSet(...) from an anonymous subclass so the set does not register globally, then call FlixelActionSet.update(float) and FlixelActionSet.endFrame() yourself.

Constructors

FlixelActionSet()

public FlixelActionSet()

Registers this set with FlixelActionSets for automatic FlixelActionSet.update(float) and FlixelActionSet.endFrame().


FlixelActionSet(boolean)

protected FlixelActionSet(boolean registerForGlobalLifecycle)

Parameters:

NameDescription
registerForGlobalLifecycleWhen true, registers with FlixelActionSets. Tests may pass false and call FlixelActionSet.update(float) / FlixelActionSet.endFrame() manually.

Fields

members

protected final Array<FlixelAction> members

steamReader

public FlixelSteamActionReader steamReader

Optional Steam Input bridge; when non-null, digital and analog actions also read these values each FlixelActionSet.update(float). Implement outside core with steamworks4j or similar.


Methods

add(FlixelAction)

protected void add(FlixelAction action)

Adds an action to this set and assigns ownership for Steam name resolution and lifecycle.

Parameters:

NameDescription
actionNon-null action instance.

update(float)

public void update(float elapsed)

Steps all member actions. Called from FlixelActionSets.update(float) after gamepads update.

Parameters:

NameDescription
elapsedFrame delta in seconds.

endFrame()

public void endFrame()

Finalizes edge detection for digital and analog actions. Called from FlixelActionSets.endFrameAll() after keys, mouse, and gamepads endFrame().


destroy()

public void destroy()