Skip to content

Controls (Virtual Gamepad)

Ready-to-use touch joystick and action buttons. JS/Web only — not available in Godot or Unity.

controls.show

Renders the virtual gamepad overlay on screen.

js
gametegra.controls.show({ opacity: 0.8, joystick: true })

Parameters:

NameTypeRequiredDescription
themestringNoVisual theme for the controls.
opacitynumberNoOpacity of the controls overlay (0-1).
joystickbooleanNoWhether to show the joystick.
buttonsarrayNoButton configurations to display.

controls.hide

Hides the virtual gamepad overlay without destroying it.

js
gametegra.controls.hide()

controls.on

Registers a listener for a specific control input event.

js
const unsub = gametegra.controls.on('joystick', (e) => { movePlayer(e.x, e.y) })

Parameters:

NameTypeRequiredDescription
codestringYesControl event code (e.g. 'joystick', 'buttonA').
fnfunctionYesCallback function receiving the event data.

Response:

json
{
  "code": "fire",
  "type": "press",
  "timestamp": 1712000000000
}

controls.onAny

Registers a listener for all control input events.

js
gametegra.controls.onAny((code, event) => { console.log(code, event) })

Parameters:

NameTypeRequiredDescription
fnfunctionYesCallback receiving all control events.

Response:

json
{
  "code": "up",
  "type": "move",
  "timestamp": 1712000000001
}

controls.destroy

Completely destroys the controls — removes DOM elements, CSS, and all event listeners.

js
gametegra.controls.destroy()