FlixelActionAnalog
View sourceclass
org.flixelgdx.input.action.FlixelActionAnalog
Two-axis vector built from FlixelAnalogBinding contributors plus optional Steam analog for FlixelActionAnalog.getName().
How values combine
Each frame, key halves add -1, 0, or +1 per axis; Flixel.gamepads axis bindings add smooth stick values. Steam FlixelSteamActionReader.getAnalogX(String) / getAnalogY are added on top. The result is clamped to a maximum length of 1 so diagonals do not exceed unit speed when mixing keys and sticks.
Typical setup
move = new FlixelActionAnalog("move");
move.addBinding("negX", FlixelAnalogBinding.negXKey(FlixelKey.LEFT));
move.addBinding("posX", FlixelAnalogBinding.posXKey(FlixelKey.RIGHT));
move.addBinding("negY", FlixelAnalogBinding.negYKey(FlixelKey.DOWN));
move.addBinding("posY", FlixelAnalogBinding.posYKey(FlixelKey.UP));
move.addBinding("stickX", FlixelAnalogBinding.gamepadAxisX(0, FlixelGamepadButton.AXIS_LEFT_X));
move.addBinding("stickY", FlixelAnalogBinding.gamepadAxisY(0, FlixelGamepadButton.AXIS_LEFT_Y));
Reading
Use FlixelActionAnalog.getX() and FlixelActionAnalog.getY() after super.update(elapsed) in your state. FlixelActionAnalog.getPrevX() / FlixelActionAnalog.getPrevY() mirror the previous frame after FlixelActionSet.endFrame(). FlixelActionAnalog.moved() is a small helper for non-zero length.
Flick detection and hold-repeat
FlixelActionAnalog.flicked() returns true for exactly one frame when the stick first crosses FlixelActionAnalog.flickThreshold. It resets to false as long as the stick stays past the threshold, and fires again only after the stick returns below the threshold and crosses it again. This mirrors the single-frame contract of FlixelActionDigital.justPressed() and is useful for menu navigation where each stick deflection should trigger exactly one action.
FlixelActionAnalog.flickedRepeating() extends that with hold-repeat: it fires on the initial flick, then fires again after FlixelAction.holdDelay seconds if the stick is still past the threshold, and continues every FlixelAction.holdInterval seconds after that. Use this for menus that should keep scrolling when the stick is held.
// Navigate a menu; hold the stick to keep scrolling.
if (navigate.flickedRepeating()) {
if (navigate.getY() > 0) selectPreviousItem();
else if (navigate.getY() < 0) selectNextItem();
}
Key bindings contribute +-1.0 per axis, so pressing any bound key immediately exceeds the default threshold and fires both methods on that frame. Adjust FlixelActionAnalog.flickThreshold before the game loop if your game needs a different sensitivity.
Constructors
FlixelActionAnalog(String)
Methods
clearBindings()
Removes all bindings from this action.
Use this before re-populating bindings from scratch, or to leave an action with no active sources (it will produce a zero vector until at least one binding is added again).
addBinding(String, FlixelAnalogBinding)
Adds a binding under a named slot (allocation-free after this call).
If a binding is already registered under slot, it is removed and replaced. Named slots are the natural model for a rebinding screen: one slot per axis or device, replaced in-place when the player picks a new key or stick.
move.addBinding("leftKey", FlixelAnalogBinding.negXKey(FlixelKey.LEFT));
move.addBinding("rightKey", FlixelAnalogBinding.posXKey(FlixelKey.RIGHT));
move.addBinding("stick", FlixelAnalogBinding.gamepadAxisX(0, FlixelGamepadButton.AXIS_LEFT_X));
// Player rebinds the left key at runtime.
move.addBinding("leftKey", FlixelAnalogBinding.negXKey(newKey));
Parameters:
| Name | Description |
|---|---|
slot | Non-null, non-empty identifier for this binding (for example "leftKey"). |
binding | Non-null binding. |
removeBinding(String)
Removes the binding registered under the given slot name.
Parameters:
| Name | Description |
|---|---|
slot | Slot name passed to FlixelActionAnalog.addBinding(String, FlixelAnalogBinding). |
Returns: true if a binding was found and removed, false if the slot was unknown.
removeBinding(FlixelAnalogBinding)
Removes a specific binding by reference identity.
If the binding was added via FlixelActionAnalog.addBinding(String, FlixelAnalogBinding), its slot entry is also cleared.
Parameters:
| Name | Description |
|---|---|
binding | The exact binding instance to remove. |
Returns: true if the binding was found and removed.
getBinding(String)
Returns the binding registered under the given slot name, or null if the slot is unknown.
Parameters:
| Name | Description |
|---|---|
slot | Slot name passed to FlixelActionAnalog.addBinding(String, FlixelAnalogBinding). |
Returns: The registered binding, or null if no binding is registered under that slot.
getX()
getY()
getPrevX()
getPrevY()
getFlickThreshold()
setFlickThreshold(float)
moved()
flicked()
Returns true for the single frame when the stick first crosses FlixelActionAnalog.flickThreshold.
Stays false while the stick remains past the threshold, and fires again only after the stick drops below it and crosses it once more. This mirrors the single-frame contract of FlixelActionDigital.justPressed(), making it safe to use for menu navigation where one deflection should trigger exactly one action.
Key and button bindings contribute +-1.0 per axis, so any bound key press that brings the magnitude past FlixelActionAnalog.flickThreshold fires flicked() on that frame.
Returns: true for one frame when the stick crosses the threshold from below.
flickedRepeating()
Returns true on the initial flick and again on each hold-repeat tick.
Fires on the same frame as FlixelActionAnalog.flicked() when the stick first crosses FlixelActionAnalog.flickThreshold, then fires again after FlixelAction.holdDelay seconds if the stick is still past the threshold, and continues every FlixelAction.holdInterval seconds after that. Returning the stick below the threshold resets the timer.
Use this instead of FlixelActionAnalog.flicked() when a held stick deflection should keep triggering, such as scrolling through a long menu list.
if (navigate.flickedRepeating()) {
if (navigate.getY() > 0) selectPreviousItem();
else if (navigate.getY() < 0) selectNextItem();
}
Returns: true on the initial flick frame and on each repeat tick while held past the threshold.