Skip to main content

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:

TopicPage
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.

Paired controller transport claiming a slot, player selection committing assignments, the runtime adapter remapping normalized input, and game presentation returning to the clientPaired controller transport claiming a slot, player selection committing assignments, the runtime adapter remapping normalized input, and game presentation returning to the client

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 GameInput helpers inside gameplay, menu, pause, and diagnostics scenes.
  • Use Hs2dControlInputManager and the pairing scenes only where a player needs to connect or inspect paired controllers.
  • Register PairedControlsInputAdapter with 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

SourceWhat to read there
../games/hosanna-ui/src/hosanna-game/core/GameInput.tsNormalized input object and button vocabulary.
../games/hosanna-ui/src/hosanna-game/input/GameInputAdapterManager.tsAdapter registration, ticking, dispatch, and drain flow.
../games/hosanna-ui/src/hosanna-game/control/Hs2dControlInput.tsHs2d helper functions for single-player and per-player routing.
../games/hosanna-ui/src/hosanna-game/control/Hs2dControlInputManager.tsPaired controller manager and conversion into GameInput.
../games/hosanna-ui/src/hosanna-game/control/PairedControlsInputAdapter.tsAdapter that feeds paired controller inputs into the runtime queue.
../hosanna-ui-game-samples-public/src/hosanna-game-examples/native-shoot-em-up/VerticalShooterLevelScene.tsReal single-player movement, pause, music toggle, and axis handling.
../hosanna-ui-game-samples-public/src/hosanna-game-examples/native-shoot-em-up/VerticalShooterPauseScene.tsPairing and controller-state scene entry points from a pause menu.
Talk to us