Skip to main content

FlixelActionAnalog

View source

class

org.flixelgdx.input.action.FlixelActionAnalog

public final class FlixelActionAnalog extends FlixelAction

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)

public FlixelActionAnalog(String name)

Methods

clearBindings()

public void 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)

public void addBinding(String slot, FlixelAnalogBinding binding)

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:

NameDescription
slotNon-null, non-empty identifier for this binding (for example "leftKey").
bindingNon-null binding.

removeBinding(String)

public boolean removeBinding(String slot)

Removes the binding registered under the given slot name.

Parameters:

NameDescription
slotSlot name passed to FlixelActionAnalog.addBinding(String, FlixelAnalogBinding).

Returns: true if a binding was found and removed, false if the slot was unknown.


removeBinding(FlixelAnalogBinding)

public boolean removeBinding(FlixelAnalogBinding binding)

Removes a specific binding by reference identity.

If the binding was added via FlixelActionAnalog.addBinding(String, FlixelAnalogBinding), its slot entry is also cleared.

Parameters:

NameDescription
bindingThe exact binding instance to remove.

Returns: true if the binding was found and removed.


getBinding(String)

public FlixelAnalogBinding getBinding(String slot)

Returns the binding registered under the given slot name, or null if the slot is unknown.

Parameters:

NameDescription
slotSlot name passed to FlixelActionAnalog.addBinding(String, FlixelAnalogBinding).

Returns: The registered binding, or null if no binding is registered under that slot.


getX()

public float getX()

getY()

public float getY()

getPrevX()

public float getPrevX()

getPrevY()

public float getPrevY()

getFlickThreshold()

public float getFlickThreshold()

setFlickThreshold(float)

public void setFlickThreshold(float flickThreshold)

moved()

public boolean moved()

flicked()

public boolean 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()

public boolean 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.