-
Notifications
You must be signed in to change notification settings - Fork 8
docs(sdk7): document TouchScreenControls and UiInputBinding for custom mobile controls #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EibrielInv
wants to merge
10
commits into
main
Choose a base branch
from
feature/custom-controlls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
42a007e
controls customization
EibrielInv da78947
removing notes, fixing images
EibrielInv 447607d
adding touch controls images
EibrielInv db8dc50
adding binding image
EibrielInv 3ab229e
docs(sdk7): embed control images on input-on-mobile + document priori…
EibrielInv fa37fbb
docs(sdk7): restructure custom-controls pages in a task-oriented style
EibrielInv b2c4d28
docs(sdk7): add control-ordering figure, link InputAction refs, tight…
EibrielInv 6ffb989
docs(sdk7): correct overflow threshold — "+" appears above 5 visible …
EibrielInv d741fd8
docs(sdk7): update button icon to TextureUnion (content-path only)
EibrielInv 1c58271
docs(sdk7): link TextureUnion to ui_background + surface uiInputBindi…
EibrielInv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| --- | ||
| description: Bind input actions to your own UI elements so they drive player input. | ||
| --- | ||
|
|
||
| # UI Input Binding | ||
|
|
||
| `UiInputBinding` turns any UI element into a control button. Bind an element to one or more [`InputAction`](../interactivity/button-events/click-events.md#pointer-buttons)s, and while it's pressed — by touch or pointer — those actions are held down, driving both the local player's input (movement, jumping) and any scene [`InputAction`](../interactivity/button-events/click-events.md#pointer-buttons) listeners, exactly like the native on-screen buttons. | ||
|
|
||
| Use it to build your own touch controls. It's typically paired with [On-screen Controls](../interactivity/touch-screen-controls.md): hide the native buttons, then put your own in their place. | ||
|
|
||
| <figure><img src="../../images/touch-controls/ui-input-binding.jpg" alt="A retro-style gamepad assembled from custom UI elements, each wired to an input action"><figcaption><p>A fully custom gamepad built from UI elements — each button is a UI entity bound to an input action</p></figcaption></figure> | ||
|
|
||
| ## Bind an action to a UI element | ||
|
|
||
| Add a `uiInputBinding` prop to any element in your `.tsx` UI and list the actions to hold while it's pressed. The prop is available on every UI element ([`UiEntity`](onscreen-ui.md#ui-entities), [`Button`](onscreen-ui.md#ui-entities), [`Label`](onscreen-ui.md#ui-entities), …), just like `uiTransform` and `uiBackground`. | ||
|
|
||
| **A button that moves the player forward while held:** | ||
|
|
||
| ```tsx | ||
| import { InputAction } from '@dcl/sdk/ecs' | ||
| import { Button } from '@dcl/sdk/react-ecs' | ||
|
|
||
| export const forwardButton = () => ( | ||
| <Button | ||
| value="▲" | ||
| uiTransform={{ width: 100, height: 100 }} | ||
| uiInputBinding={{ actions: [InputAction.IA_FORWARD] }} | ||
| /> | ||
| ) | ||
| ``` | ||
|
|
||
| ## Build a custom control cluster | ||
|
|
||
| Combine several bound elements to assemble a full control scheme. | ||
|
|
||
| **A movement button plus an action button that fires `IA_PRIMARY`:** | ||
|
|
||
| ```tsx | ||
| import { InputAction } from '@dcl/sdk/ecs' | ||
| import { Button, UiEntity } from '@dcl/sdk/react-ecs' | ||
|
|
||
| export const customControls = () => ( | ||
| <UiEntity uiTransform={{ width: 240, height: 120 }}> | ||
| <Button | ||
| value="▲" | ||
| uiTransform={{ width: 100, height: 100 }} | ||
| uiInputBinding={{ actions: [InputAction.IA_FORWARD] }} | ||
| /> | ||
| <Button | ||
| value="Use" | ||
| uiTransform={{ width: 100, height: 100 }} | ||
| uiInputBinding={{ actions: [InputAction.IA_PRIMARY] }} | ||
| /> | ||
| </UiEntity> | ||
| ) | ||
| ``` | ||
|
|
||
| The bound actions behave just like the native buttons: `IA_FORWARD` / `IA_BACKWARD` / `IA_LEFT` / `IA_RIGHT` move the avatar, and any action can be read by your scene's [`InputAction`](../interactivity/button-events/click-events.md#pointer-buttons) listeners. Removing the prop (or the component) releases the binding. | ||
|
|
||
| ## Properties | ||
|
|
||
| | Property | Type | Description | | ||
| | --- | --- | --- | | ||
| | `actions` | array of [`InputAction`](../interactivity/button-events/click-events.md#pointer-buttons) | The input actions held down while this element is pressed. See [Click events](../interactivity/button-events/click-events.md) for the full list of [`InputAction`](../interactivity/button-events/click-events.md#pointer-buttons) values. | | ||
|
|
||
| {% hint style="info" %} | ||
| Pair this with [`TouchScreenControls`](../interactivity/touch-screen-controls.md) to hide the native controls and replace them with your own touch UI — the recommended way to ship a fully custom control scheme. | ||
| {% endhint %} | ||
|
|
||
| ## Related | ||
|
|
||
| * [On-screen Controls](../interactivity/touch-screen-controls.md) | ||
| * [UI Button Events](ui_button_events.md) | ||
| * [Input on mobile](../building-for-mobile/input-on-mobile.md) | ||
| * [Click events](../interactivity/button-events/click-events.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add image here