Skip to content

1681-engine / index / Actions

Class: Actions<A> ​

Defined in: src/input/Actions.ts:50

Type Parameters ​

Type Parameter
A extends string

Constructors ​

Constructor ​

ts
new Actions<A>(
   keyboard, 
   bindings, 
   options?
): Actions<A>;

Defined in: src/input/Actions.ts:69

Parameters ​

ParameterType
keyboardKeyboard | null
bindingsBindings<A>
optionsActionsOptions

Returns ​

Actions<A>

Accessors ​

replaying ​

Get Signature ​

ts
get replaying(): boolean;

Defined in: src/input/Actions.ts:137

Whether a replay is driving the actions now.

Returns ​

boolean

Methods ​

axis() ​

ts
axis(negative, positive): number;

Defined in: src/input/Actions.ts:178

value(positive) - value(negative), in −1…1.

Parameters ​

ParameterType
negativeA
positiveA

Returns ​

number


bind() ​

ts
bind(action, inputs): void;

Defined in: src/input/Actions.ts:81

Replaces one action's bindings (a player's rebinding).

Parameters ​

ParameterType
actionA
inputsreadonly string[]

Returns ​

void


bindingsOf() ​

ts
bindingsOf(action): readonly string[];

Defined in: src/input/Actions.ts:85

Parameters ​

ParameterType
actionA

Returns ​

readonly string[]


down() ​

ts
down(action): boolean;

Defined in: src/input/Actions.ts:158

Held this step.

Parameters ​

ParameterType
actionA

Returns ​

boolean


endStep() ​

ts
endStep(): void;

Defined in: src/input/Actions.ts:191

Ends the step: the keyboard forgets its edges; virtual taps shorter than a step have now been seen.

Returns ​

void


flush() ​

ts
flush(): void;

Defined in: src/input/Actions.ts:201

Drops every pending edge: what went down or up since the last step is forgotten, and what is held now counts as already held, so the next poll reports no pressed or released for it. For input that sat unread while something else had the keys (a pause menu over the level; SceneManager.pop calls it through Scene.useInput).

Returns ​

void


poll() ​

ts
poll(): void;

Defined in: src/input/Actions.ts:111

Reads every device once; call at the start of each simulation step.

Returns ​

void


press() ​

ts
press(name): void;

Defined in: src/input/Actions.ts:90

A touch UI's virtual button went down: touch:<name> bindings read it.

Parameters ​

ParameterType
namestring

Returns ​

void


pressed() ​

ts
pressed(action): boolean;

Defined in: src/input/Actions.ts:168

Went down this step.

Parameters ​

ParameterType
actionA

Returns ​

boolean


release() ​

ts
release(name): void;

Defined in: src/input/Actions.ts:95

Parameters ​

ParameterType
namestring

Returns ​

void


released() ​

ts
released(action): boolean;

Defined in: src/input/Actions.ts:173

Came up this step.

Parameters ​

ParameterType
actionA

Returns ​

boolean


replay() ​

ts
replay(source): void;

Defined in: src/input/Actions.ts:132

Takes each step's values from source instead of the devices (an InputPlayer), until it returns null; then the devices answer again. Pass null to stop at once.

Parameters ​

ParameterType
source(() => ReadonlyMap<A, number> | null) | null

Returns ​

void


rumble() ​

ts
rumble(options, padIndex?): Promise<boolean>;

Defined in: src/input/Actions.ts:103

Rumbles the gamepads the actions read: every connected one, or only padIndex among them. Resolves true when any played; a pad without rumble is skipped silently.

Parameters ​

ParameterType
optionsRumbleOptions
padIndex?number

Returns ​

Promise<boolean>


tap() ​

ts
tap(tap): () => void;

Defined in: src/input/Actions.ts:142

Calls tap with every step's values right after poll (an InputRecorder); returns the stop.

Parameters ​

ParameterType
tap(values) => void

Returns ​

() => void


value() ​

ts
value(action): number;

Defined in: src/input/Actions.ts:163

How far it is held (0–1): 1 for a key, the trigger or stick amount for analog input.

Parameters ​

ParameterType
actionA

Returns ​

number


vector() ​

ts
vector(
   left, 
   right, 
   up, 
   down
): [number, number];

Defined in: src/input/Actions.ts:183

A 2D direction from four actions, never longer than 1 (a diagonal is not faster).

Parameters ​

ParameterType
leftA
rightA
upA
downA

Returns ​

[number, number]

Released under the MIT License.