Gamepad Support
Yin.Story supports gamepad input across the editor, story browser, and web-based stories.
Default Mapping
| Button | Action |
|---|---|
| A | Confirm / Select |
| B | Back (when a back event with history = -1 exists) |
| D-pad / Left Stick | Navigate focus / Switch options |
| X | Auxiliary action (scene-defined) |
| Y | Auxiliary action |
| Start | Start / Menu |
| Select | Select |
| LB / RB | Left/Right bumpers |
| LT / RT | Left/Right triggers |
| LS / RS | Stick press |
Auto-Focus
The system automatically manages gamepad focus between event buttons in a scene. Moving the d-pad triggers focus jumps based on layout:
- Horizontal layout: left/right navigation
- Vertical layout: up/down navigation
- Cross-component focus automatically snaps to the nearest element
Background Loop
Gamepad input is polled continuously via requestAnimationFrame and pauses automatically when the page is not visible, reducing resource usage.
Custom Binding
Access gamepad state in scripts:
js
import { gamepad } from '@/assets/gamepad.js'
// Register custom events
gamepad.on('A', () => {
// A button pressed
})
// Currently hovered element ID
import { gamepadHover } from '@/assets/gamepad.js'