> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/scenes-sdk7/interactivity/touch-screen-controls.md).

# On-screen Controls

Configure the native on-screen touch controls for your scene.

On the mobile client, players interact with your scene through a set of native on-screen controls — a virtual joystick, a crosshair, and a gamepad of buttons. The `TouchScreenControls` component lets your scene reshape that HUD: declutter it, hide the joystick or crosshair, change what the large central button does, swap a button's glyph for your own icon, or hide buttons entirely and replace them with your own UI.

<figure><img src="https://45449780-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-15146380df30e490d11a9f8ddc16b25c14999586%2Ftouch-controls-default.webp?alt=media" alt="The default mobile HUD: virtual joystick on the left, and on the right the large jump button with the interaction and E buttons beside it"><figcaption><p>The default on-screen controls, before any customization: jump, interaction and E</p></figcaption></figure>

{% hint style="info" %}
The component is applied automatically while the player is inside your scene, and the client restores its own controls the moment they leave. It only affects platforms with native on-screen controls: it's a no-op on desktop and has no effect in VR.
{% endhint %}

## What shows by default

From SDK `7.32.0`, every scene starts with three gamepad buttons visible:

* `IA_JUMP`, the large central button
* `IA_POINTER`, the interaction button
* `IA_PRIMARY`, the E button

`IA_SECONDARY` and `IA_ACTION_3` to `IA_ACTION_6` start hidden. You only need `TouchScreenControls` when you want something other than this.

{% hint style="warning" %}
**📔 Note**: The three-button default and the `showDefault()` helper need SDK `7.32.0` or later. On earlier versions all eight buttons show unless your scene hides some, and `showDefault()` doesn't exist, so `showAll()` is the only way to bring buttons back.
{% endhint %}

The SDK writes that default set once at scene start, just before the first frame, and skips it when your scene already chose its own buttons. Your scene counts as having chosen if either:

* One of the button visibility helpers already ran: `hideAll()`, `showAll()`, `showDefault()` or `hide()`. This happens when you call one at the top level of `index.ts`, outside `main()`.
* The component on the root entity already lists at least one button, for example because your scene wrote it with `createOrReplace` at the top level of `index.ts`, outside `main()`.

`hideJoystick()`, `showJoystick()`, `hideCrosshair()`, `showCrosshair()` and `setMainAction()` don't count: the default button set still applies alongside them.

Your `main()` function runs after that write, so anything you do there lands on top of the default set. Call the helpers inside `main()` or later, not at the top level, or the default set is skipped. A helper like `hide()` merges with it, while `createOrReplace` replaces the whole list with yours.

To bring the hidden buttons back, call `showAll()` for all eight. `showDefault()` restores the default set and leaves your icons, joystick, crosshair and main action untouched.

```ts
import { TouchScreenControls } from '@dcl/sdk/ecs'

export function main() {
	// Show every on-screen button, including the 1 / 2 / 3 / 4 buttons
	TouchScreenControls.showAll()
}
```

{% hint style="warning" %}
Reacting to F or 1–4 through `PointerEvents` or `inputSystem` does **not** show the button. If your scene uses them, turn them on with `TouchScreenControls`, or mobile players can't reach them.
{% endhint %}

{% hint style="info" %}
A scene that removes the component (`TouchScreenControls.deleteFrom(engine.RootEntity)`) shows all eight buttons.
{% endhint %}

## How the button layout works

The gamepad buttons form a single **priority stack**. The order is fixed:

1. `IA_JUMP`
2. `IA_POINTER`
3. `IA_PRIMARY` (E)
4. `IA_SECONDARY` (F)
5. `IA_ACTION_3` (1)
6. `IA_ACTION_4` (2)
7. `IA_ACTION_5` (3)
8. `IA_ACTION_6` (4)

The on-screen positions are fixed too. The **visible** buttons fill those positions from the top of the stack down — so what you change is *which* buttons are visible and *which one leads*, not their order.

| When you…                                      | The controls…                                                                                                                                                                        |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Hide a button** (any button, including jump) | Every lower-priority button moves up to fill the gap. Hide jump and `IA_POINTER` takes the central spot.                                                                             |
| **Change nothing**                             | The default set applies: `IA_JUMP` is the large central button, with `IA_POINTER` and `IA_PRIMARY` in the slots around it.                                                           |
| **Set a main button** with `mainAction`        | That action jumps to the front and becomes the central button; every other button keeps its normal order.                                                                            |
| **Set a main button that is also hidden**      | Hiding wins — the button stays hidden. This includes F and 1–4, which start hidden: turn the button on as well (see **Change the main button** under [Common tasks](#common-tasks)). |
| **Leave 5 or fewer buttons visible**           | All of them show directly (the central button plus up to four around it); there is no "+" menu.                                                                                      |
| **Leave more than 5 buttons visible**          | The "+" takes the last slot, so four show directly (the central button plus three) and the rest sit behind the "+" overflow toggle.                                                  |

<figure><img src="https://45449780-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-2c1bf3ebb2a4c72f91fbd85fd13e64e823f94260%2Fcontrol-ordering.webp?alt=media" alt="Three HUDs showing the gamepad reflowing as the number of visible buttons changes"><figcaption><p>How the buttons reflow with the visible count. <strong>Left (7 buttons):</strong> the main button, an arc of 1–3, and the "+" holding the overflow (4–7) in a column that climbs upward. <strong>Center (5 buttons):</strong> the same arc, with a shorter overflow column (4–5) behind the "+". <strong>Right (4 buttons):</strong> all four show directly and the "+" disappears.</p></figcaption></figure>

{% hint style="info" %}
The `1`/`2`/`3`/`4` buttons start hidden. `showAll()` brings them back, but that leaves eight visible buttons, so the lowest-priority ones end up behind the "+". To put a numbered button directly on screen, keep the visible count at five or fewer: show only the buttons your scene actually uses.
{% endhint %}

## Common tasks

`TouchScreenControls` ships a set of convenience helpers. Each one writes the component onto the scene's `RootEntity` (where the client reads it) and merges with the current value. Call them inside `main()` or later: at the top level of `index.ts` they run before the default set is written, and it's skipped.

**Change the main button** — make the large central button trigger a different action:

```ts
import { TouchScreenControls, InputAction } from '@dcl/sdk/ecs'

export function main() {
	TouchScreenControls.setMainAction(InputAction.IA_PRIMARY)
}
```

`setMainAction()` doesn't turn a button on. To lead with F or a numbered button, turn it on as well, or it stays hidden:

```ts
import { TouchScreenControls, InputAction } from '@dcl/sdk/ecs'

export function main() {
	TouchScreenControls.showAll()
	TouchScreenControls.hide([
		InputAction.IA_ACTION_3,
		InputAction.IA_ACTION_4,
		InputAction.IA_ACTION_5,
		InputAction.IA_ACTION_6,
	])
	TouchScreenControls.setMainAction(InputAction.IA_SECONDARY)
}
```

**Hide the joystick or crosshair** — remove the movement stick and/or the aiming reticle, and bring them back with their `show` counterparts:

```ts
TouchScreenControls.hideJoystick()
TouchScreenControls.hideCrosshair()

// and to bring them back:
TouchScreenControls.showJoystick()
TouchScreenControls.showCrosshair()
```

**Hide specific buttons** — pass the actions you want gone (the rest cascade up). The call adds to the buttons already hidden, so with the default set this leaves the interaction button as the central button and E beside it:

```ts
import { TouchScreenControls, InputAction } from '@dcl/sdk/ecs'

export function main() {
	TouchScreenControls.hide([InputAction.IA_JUMP])
}
```

**Use F or the numbered buttons** — they start hidden. Show every button, then hide the ones your scene doesn't use. `showAll()` also clears custom icons. If you set icons with `createOrReplace`, do it after `showAll()` and before `hide()`, because `createOrReplace` replaces the whole button list, hidden buttons included:

```ts
import { TouchScreenControls, InputAction } from '@dcl/sdk/ecs'

export function main() {
	// Show F and 1, keep 2–4 hidden
	TouchScreenControls.showAll()
	TouchScreenControls.hide([InputAction.IA_ACTION_4, InputAction.IA_ACTION_5, InputAction.IA_ACTION_6])
}
```

**Hide every button, show every button, or go back to the default set:**

```ts
import { TouchScreenControls } from '@dcl/sdk/ecs'

export function main() {
	// Pick one:
	TouchScreenControls.hideAll()     // no gamepad buttons at all
	TouchScreenControls.showAll()     // all eight buttons
	TouchScreenControls.showDefault() // jump, pointer and primary only
}
```

These three only affect the gamepad buttons. They don't restore a hidden joystick or crosshair, and they don't change your main action; use `showJoystick()` / `showCrosshair()` for those. `hideAll()` and `showDefault()` keep your custom icons, but `showAll()` clears them.

**Replace a button's icon** — for full control (custom icons, several changes at once), write the raw component on `engine.RootEntity`. This replaces the default set, so every button you don't list is shown; call `showDefault()` afterwards to hide F and 1–4 again while keeping your icons:

```ts
import { engine, TouchScreenControls, InputAction } from '@dcl/sdk/ecs'

export function main() {
	TouchScreenControls.createOrReplace(engine.RootEntity, {
		hideJoystick: false,
		hideCrosshair: true,
		mainAction: InputAction.IA_PRIMARY,
		touchInputs: [
			{
				inputAction: InputAction.IA_PRIMARY,
				hide: false,
				icon: { tex: { $case: 'texture', texture: { src: 'images/grab.png' } } },
			},
		],
	})
	TouchScreenControls.showDefault()
}
```

The helpers at a glance:

| Helper                  | What it does                                                                                                                                                    |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `setMainAction(action)` | Sets which action the large central button triggers.                                                                                                            |
| `hideJoystick()`        | Hides the native virtual joystick.                                                                                                                              |
| `showJoystick()`        | Shows the native virtual joystick again.                                                                                                                        |
| `hideCrosshair()`       | Hides the on-screen crosshair / reticle.                                                                                                                        |
| `showCrosshair()`       | Shows the on-screen crosshair / reticle again.                                                                                                                  |
| `hide(actions)`         | Hides the given gamepad buttons (merged into the current config).                                                                                               |
| `hideAll()`             | Hides every gamepad button.                                                                                                                                     |
| `showAll()`             | Shows all eight gamepad buttons, clearing every per-button entry (custom icons included). Does **not** affect the joystick/crosshair.                           |
| `showDefault()`         | Restores the default set: jump, pointer and primary visible, secondary and actions 3 to 6 hidden. Keeps icons, joystick, crosshair and main action as they are. |

## Properties

Write these directly when you use `createOrReplace`. `hideJoystick`, `hideCrosshair`, `touchInputs` and each entry's `hide` are required by the TypeScript type:

| Property        | Type                                                                                                                           | Description                                                                                                                                                                                                                                                                                                                                               |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `hideJoystick`  | *boolean*                                                                                                                      | Hides the native virtual movement joystick.                                                                                                                                                                                                                                                                                                               |
| `hideCrosshair` | *boolean*                                                                                                                      | Hides the on-screen crosshair / reticle.                                                                                                                                                                                                                                                                                                                  |
| `mainAction`    | [*InputAction*](https://docs.decentraland.org/creator/scenes-sdk7/interactivity/button-events/click-events.md#pointer-buttons) | Moves this action to the front of the stack, making it the large central button; the other buttons keep their order. Only gamepad actions are valid (see below). When unset, the first visible button (`IA_JUMP` by default) leads. It doesn't show a hidden button, F and 1–4 included. See [How the button layout works](#how-the-button-layout-works). |
| `touchInputs`   | *array*                                                                                                                        | Per-button overrides. Writing this field replaces the whole list, so any button you leave out is shown with its default glyph, including the ones that start hidden.                                                                                                                                                                                      |

Each `touchInputs` entry has:

| Field         | Type                                                                                                                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `inputAction` | [*InputAction*](https://docs.decentraland.org/creator/scenes-sdk7/interactivity/button-events/click-events.md#pointer-buttons) | Which on-screen button this entry configures.                                                                                                                                                                                                                                                                                                                                                                                                             |
| `hide`        | *boolean*                                                                                                                      | Hides this button. Default is `false` (shown). Any button can be hidden, **including `IA_JUMP`** — the rest cascade up to fill its place.                                                                                                                                                                                                                                                                                                                 |
| `icon`        | [*TextureUnion*](https://docs.decentraland.org/creator/scenes-sdk7/2d-ui/ui_background.md#background) (optional)               | Overrides the button glyph with a scene image. Use the `texture` variant with a content-mapped `src` (an image included in your scene) — `{ tex: { $case: 'texture', texture: { src: 'images/grab.png' } } }`. Only scene-content paths are supported (not external URLs, avatar or video textures). For the jump button this replaces all of its dynamic states (jump / double-jump / glide). If the path can't be resolved, the built-in glyph is used. |

## Which actions map to which buttons

The [`InputAction`](https://docs.decentraland.org/creator/scenes-sdk7/interactivity/button-events/click-events.md#pointer-buttons) values here are the same ones used across [Input on mobile](https://docs.decentraland.org/creator/build-for-mobile/develop/input-on-mobile.md) and [Click events](https://docs.decentraland.org/creator/scenes-sdk7/interactivity/button-events/click-events.md). These are the actions that map to on-screen buttons:

| InputAction                                                   | On-screen button                   |
| ------------------------------------------------------------- | ---------------------------------- |
| `IA_JUMP`                                                     | The large central button (default) |
| `IA_POINTER`                                                  | The interaction button             |
| `IA_PRIMARY`                                                  | The E button                       |
| `IA_SECONDARY`                                                | The F button                       |
| `IA_ACTION_3` / `IA_ACTION_4` / `IA_ACTION_5` / `IA_ACTION_6` | The 1 / 2 / 3 / 4 buttons          |

{% hint style="warning" %}
`IA_ANY` and `IA_MODIFIER` are meta values — they don't map to a button and can't be used here.
{% endhint %}

## Example

To hide the joystick, show the F button, keep the numbered buttons hidden, and give the central jump button a custom icon shipped in your scene:

```ts
import { engine, TouchScreenControls, InputAction } from '@dcl/sdk/ecs'

export function main() {
	TouchScreenControls.createOrReplace(engine.RootEntity, {
		hideJoystick: true,
		hideCrosshair: false,
		touchInputs: [
			// This list replaces the default one, so the numbered buttons have to be
			// listed here to stay hidden
			{ inputAction: InputAction.IA_SECONDARY, hide: false },
			{ inputAction: InputAction.IA_ACTION_3, hide: true },
			{ inputAction: InputAction.IA_ACTION_4, hide: true },
			{ inputAction: InputAction.IA_ACTION_5, hide: true },
			{ inputAction: InputAction.IA_ACTION_6, hide: true },
			{
				inputAction: InputAction.IA_JUMP,
				hide: false,
				icon: { tex: { $case: 'texture', texture: { src: 'images/banana.png' } } },
			},
		],
	})
}
```

<figure><img src="https://45449780-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-e8fa39c0bb21eb9c2ff7949a101321cc1549f937%2Fcustom-main-action.webp?alt=media" alt="A mobile HUD with the joystick hidden, the E and F buttons beside the interaction button, and the central jump button showing a custom banana icon"><figcaption><p>The result: joystick gone, F shown, numbered buttons hidden (so the "+" disappears), and the jump button re-iconed</p></figcaption></figure>

To replace the native controls entirely, hide them here and build your own touch buttons with [UI Input Binding](https://docs.decentraland.org/creator/scenes-sdk7/2d-ui/ui_input_binding.md).

## Related

* [UI Input Binding](https://docs.decentraland.org/creator/scenes-sdk7/2d-ui/ui_input_binding.md)
* [Input on mobile](https://docs.decentraland.org/creator/build-for-mobile/develop/input-on-mobile.md)
* [Click events](https://docs.decentraland.org/creator/scenes-sdk7/interactivity/button-events/click-events.md)
* [Detect the platform from code](https://docs.decentraland.org/creator/build-for-mobile/develop/detect-platform.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/scenes-sdk7/interactivity/touch-screen-controls.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
