Input And Controller Pairing
Hs2d games consume normalized GameInput objects. Paired phone/web controllers are one producer of those inputs, but they are not the input model itself. Keep the concepts separate:
| Topic | Page |
|---|---|
GameInput, input phases, button aliases, player routing helpers, and scene handling patterns. | Game Input |
Pairing server lifecycle, controller slots, protocol conversion, and PairedControlsInputAdapter. | Controller Pairing |
| Pairing/debug scenes, player-character assignment, hosted presentation, motion, and custom controls. | Controller Pairing Scenes And Presentation |
Runtime Shape
The runtime ticks input adapters, drains queued GameInput objects, and passes the array into the active game or scene. A scene should handle normalized buttons and player metadata, not raw Roku key codes or controller WebSocket messages.
protected override handleInputs(inputs: GameInput[]): boolean {
for (const input of inputs) {
if (input.release) continue;
if (input.isButton('play')) {
this.game?.pushScene(new MyPauseScene(this.pauseOptions));
return true;
}
}
return false;
}
Common Split
- Use
GameInputhelpers inside gameplay, menu, pause, and diagnostics scenes. - Use
Hs2dControlInputManagerand the pairing scenes only where a player needs to connect or inspect paired controllers. - Register
PairedControlsInputAdapterwith the input adapter manager when paired controllers should feed runtime input. - Route gameplay by
playerIndex; host remote input usually has no player index.
Source References
| Source | What to read there |
|---|---|
../games/hosanna-ui/src/hosanna-game/core/GameInput.ts | Normalized input object and button vocabulary. |
../games/hosanna-ui/src/hosanna-game/input/GameInputAdapterManager.ts | Adapter registration, ticking, dispatch, and drain flow. |
../games/hosanna-ui/src/hosanna-game/control/Hs2dControlInput.ts | Hs2d helper functions for single-player and per-player routing. |
../games/hosanna-ui/src/hosanna-game/control/Hs2dControlInputManager.ts | Paired controller manager and conversion into GameInput. |
../games/hosanna-ui/src/hosanna-game/control/PairedControlsInputAdapter.ts | Adapter that feeds paired controller inputs into the runtime queue. |
../hosanna-ui-game-samples-public/src/hosanna-game-examples/native-shoot-em-up/VerticalShooterLevelScene.ts | Real single-player movement, pause, music toggle, and axis handling. |
../hosanna-ui-game-samples-public/src/hosanna-game-examples/native-shoot-em-up/VerticalShooterPauseScene.ts | Pairing and controller-state scene entry points from a pause menu. |