FlixelActionSet
View sourceclass
org.flixelgdx.input.action.FlixelActionSet
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)
- Construct a subclass (or this type) after Flixel.initialize.
- In the subclass constructor, create FlixelActionDigital / FlixelActionAnalog instances, call FlixelActionSet.add(FlixelAction) for each, and add FlixelDigitalBinding / FlixelAnalogBinding instances.
- By default the set registers with FlixelActionSets; FlixelGame calls FlixelActionSets.update(float) after
Flixel.gamepads.update()and FlixelActionSets.endFrameAll() after keys, mouse, and gamepadsendFrame()inrender(). - From FlixelState.update(float) (or similar), read
jump.justPressed(),move.getX(), etc. - When the screen or mode ends, call FlixelActionSet.destroy() so the set unregisters and clears members.
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()
Registers this set with FlixelActionSets for automatic FlixelActionSet.update(float) and FlixelActionSet.endFrame().
FlixelActionSet(boolean)
Parameters:
| Name | Description |
|---|---|
registerForGlobalLifecycle | When true, registers with FlixelActionSets. Tests may pass false and call FlixelActionSet.update(float) / FlixelActionSet.endFrame() manually. |
Fields
members
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)
Adds an action to this set and assigns ownership for Steam name resolution and lifecycle.
Parameters:
| Name | Description |
|---|---|
action | Non-null action instance. |
update(float)
Steps all member actions. Called from FlixelActionSets.update(float) after gamepads update.
Parameters:
| Name | Description |
|---|---|
elapsed | Frame delta in seconds. |
endFrame()
Finalizes edge detection for digital and analog actions. Called from FlixelActionSets.endFrameAll() after keys, mouse, and gamepads endFrame().