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:
| Name | Type | Required | Description |
|---|---|---|---|
theme | string | No | Visual theme for the controls. |
opacity | number | No | Opacity of the controls overlay (0-1). |
joystick | boolean | No | Whether to show the joystick. |
buttons | array | No | Button 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:
| Name | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Control event code (e.g. 'joystick', 'buttonA'). |
fn | function | Yes | Callback 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:
| Name | Type | Required | Description |
|---|---|---|---|
fn | function | Yes | Callback 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()