Class: Actions

rune.input.Actions(keyboardopt, gamepadopt)

Use Inputs.createActions() for automatic updates before scene logic. A directly constructed collection must be updated once before its owner's game logic. Devices are borrowed and are never disposed by this collection.

Constructor

new Actions(keyboardopt, gamepadopt)

Creates a collection of named input actions and analog axes.
Parameters:
Name Type Attributes Description
keyboard rune.input.Keyboard <optional>
Keyboard to read.
gamepad rune.input.Gamepad <optional>
One player's gamepad to read.
Source:

Members

(readonly) disposed :boolean

Whether this collection has been disposed.
Type:
  • boolean
Source:

enabled :boolean

Whether actions and axes are sampled. Disabling resets both and retains bindings.
Type:
  • boolean
Default Value:
  • true
Source:

gamepad :rune.input.Gamepad

Player's gamepad. May be replaced or set to null.
Type:
Source:

keyboard :rune.input.Keyboard

Keyboard used by all actions. May be replaced or set to null.
Type:
Source:

Methods

axis(negativeName, positiveName) → {number}

Combines two actions into an axis. Both or neither held returns zero.
Parameters:
Name Type Description
negativeName string Action for -1.
positiveName string Action for 1.
Source:
Returns:
-1, 0 or 1.
Type
number

bindButton(name, button) → {rune.input.Action}

Adds a gamepad button binding, creating the action if needed.
Parameters:
Name Type Description
name string Action name.
button number Non-negative integer button ID.
Source:
Throws:
If the name, button or collection state is invalid.
Type
Error
Returns:
The action, for additional bindings.
Type
rune.input.Action

bindKey(name, key) → {rune.input.Action}

Adds a key binding, creating the action if needed.
Parameters:
Name Type Description
name string Action name.
key string Keyboard key name.
Source:
Throws:
If the name, key or collection state is invalid.
Type
Error
Returns:
The action, for additional bindings.
Type
rune.input.Action

clear() → {undefined}

Removes all actions, axes and their bindings.
Source:
Returns:
Type
undefined

create(name) → {rune.input.Action}

Creates an action, or returns the existing action with the same name.
Parameters:
Name Type Description
name string Non-empty action name.
Source:
Throws:
  • If the name is invalid.
    Type
    TypeError
  • If the collection is disposed.
    Type
    Error
Returns:
The registered action.
Type
rune.input.Action

createAxis(name) → {rune.input.Axis}

Creates an analog axis, or returns the existing axis with the same name. Axis names and action names occupy separate namespaces.
Parameters:
Name Type Description
name string Non-empty axis name.
Source:
Throws:
If the name is invalid or the collection is disposed.
Type
Error
Returns:
The registered axis.
Type
rune.input.Axis
Example
controls.bindKey("LEFT", "A");
controls.bindKey("RIGHT", "D");
controls.createAxis("MOVE_X")
    .bindActions("LEFT", "RIGHT")
    .bindStick("left", "x");
var movement = controls.getAxis("MOVE_X").value;

get(name) → (nullable) {rune.input.Action}

Finds an action without creating it. Names are matched without regard to case.
Parameters:
Name Type Description
name string Action name.
Source:
Returns:
The action, or null if missing or disposed.
Type
rune.input.Action

getAxis(name) → (nullable) {rune.input.Axis}

Finds an axis without creating it. Names are matched without regard to case.
Parameters:
Name Type Description
name string Axis name.
Source:
Returns:
The axis, or null if missing or disposed.
Type
rune.input.Axis

justPressed(name) → {boolean}

Reads whether an action became held in the current update.
Parameters:
Name Type Description
name string Action name.
Source:
Returns:
Whether just pressed. Missing actions return false.
Type
boolean

justReleased(name) → {boolean}

Reads whether the last held binding was released in the current update.
Parameters:
Name Type Description
name string Action name.
Source:
Returns:
Whether just released. Missing actions return false.
Type
boolean

pressed(name) → {boolean}

Reads the combined held state of an action.
Parameters:
Name Type Description
name string Action name.
Source:
Returns:
Whether held. Missing actions return false.
Type
boolean

remove(name) → {boolean}

Removes and disposes a named action without affecting input devices.
Parameters:
Name Type Description
name string Action name.
Source:
Returns:
Whether an action was removed.
Type
boolean

removeAxis(name) → {boolean}

Removes and disposes a named axis, leaving actions and devices unchanged.
Parameters:
Name Type Description
name string Axis name.
Source:
Returns:
Whether an axis was removed.
Type
boolean

reset() → {undefined}

Clears sampled states, retaining bindings and leaving devices unchanged.
Source:
Returns:
Type
undefined