makeActions()
Bind named actions to keys, gamepad and on-screen controls. Sources are strings: key:<KeyboardEvent.code>, pad:<PadButton> (0..1), pad:<PadAxis> (-1..1), touch:<id> (a makeTouchControls control; a joystick adds <id>.x and <id>.y), and a trailing + or - for one half of a signed source. Screen and...
function makeActions<B extends Bindings>(input: Input, defaults: B): Actions<B>;Defined in: engine/src/input/actions.ts:105
Bind named actions to keys, gamepad and on-screen controls. Sources are strings:
key:<KeyboardEvent.code>, pad:<PadButton> (0..1), pad:<PadAxis> (-1..1),
touch:<id> (a makeTouchControls control; a joystick adds <id>.x and <id>.y), and a
trailing + or - for one half of a signed source. Screen and pad Y are down-positive, so
"stick pushed up" is pad:LeftY-.
Every bound key has its default action prevented, so bound keys do not scroll the page.
Type Parameters
| Type Parameter |
|---|
B extends Bindings |
Parameters
| Parameter | Type | Description |
|---|---|---|
input | Input | The surface's input. Call input.update() once per frame before reading. |
defaults | B | The action map; it is copied, and bindings() returns the current one. |
Returns
Actions<B>
The actions, typed by the names in defaults.
Example
const actions = makeActions(input, {
strafe: axis({ negative: ["key:KeyA"], positive: ["key:KeyD"], analog: ["pad:LeftX", "touch:move.x"] }),
// Up is negative on a stick, so each half goes to the opposite side.
walk: axis({ negative: ["key:KeyS", "pad:LeftY+", "touch:move.y+"], positive: ["key:KeyW", "pad:LeftY-", "touch:move.y-"] }),
jump: button("key:Space", "pad:A", "touch:jump"),
});
// per frame, after input.update():
const [x, z] = actions.vector("strafe", "walk");
if (actions.pressed("jump")) jump();deadzone2()
Radial deadzone: below dz is zero, above it rescales so the edge still reaches 1.
makeLookController()
First-person look from mouse (pointer lock after a click, or drag without it), touch drag, the right stick and optional turn keys. Movement is gathered as events arrive and applied in update(dt), so stick and key speed is framerate-independent and the mouse is counted once.