voxolith

makeTouchControls()

Add on-screen joysticks and buttons that feed the input's virtual channel, so a game binds touch:move.x beside key:KeyA and pad:LeftX. The controls are a fixed overlay of their own elements, so fingers on them never reach the canvas gestures. DOM-only.

function makeTouchControls(input: Input, spec: TouchControlsSpec): TouchControls;

Defined in: engine/src/input/touch.ts:89

Joysticks take the lower part of their side of the screen and centre on wherever the thumb lands. Buttons stack bottom-up in two columns from the outer edge. Colours come from the CSS custom properties --vx-control-bg, --vx-control-fg and --vx-control-active.

Parameters

ParameterTypeDescription
inputInputThe surface's input.
specTouchControlsSpecThe controls to create and when to show them.

Returns

TouchControls

A handle to show, hide or remove them.

Example

makeTouchControls(input, {
  joysticks: [{ id: "move", side: "left" }],
  buttons: [{ id: "jump", label: "A" }],
});
const actions = makeActions(input, {
  strafe: axis({ negative: ["key:KeyA"], positive: ["key:KeyD"], analog: ["touch:move.x"] }),
  jump: button("key:Space", "touch:jump"),
});

On this page