FERRETGame engine over Babylon.js
Ferret

Input actions and UI

Skill ferret-input-ui · download all skills · SKILL.md

When to use#

Adding controls, showing a prompt or HUD line, building a menu, testing input.

The model#

A game declares actions (button or axis2) and per-kind bindings (keyboard, console, gamepad, touch). InputService samples every fixed step: down, pressed, released, axis, lookDelta; prompt(a) returns the label of the current binding for UI text. On OS Beroun the cursor, A and B reach the page as keys, so console is an ordinary key map.

Steps#

  1. Declare actions and bindings; pass both to createGame.
  2. Use input.pressed('use') in onFixedUpdate, never raw key codes.
  3. Phones and tablets get TouchControls from the touch bindings automatically (touchControls: false to opt out).
  4. UI: setHud(key, text|null), setPrompt(text), toast(text) (at most three at once), openMenu(def) with MenuModel (up/down/accept/back), pauseMenu.
  5. In tests: inject(action, value); enabled = false while a menu or cutscene is up.

Check afterwards#

Play every action with each binding kind; open the menu with only cursor, A and B; the prompt text matches the active kind.

What usually goes wrong#

  • Binding extra console buttons: apps use the cursor, A (Enter) and B (Exit) only unless the owner allows more.
  • Writing menu code that needs a mouse: use MenuModel so D-pad, A, B, mouse and touch all work.
  • HUD sizes in pixels instead of em.
  • Forgetting to disable input while a menu is open.

Files#