Platform and display
Skill ferret-platform-display · download all skills · SKILL.md
When to use#
Saving or loading game state, reacting to suspend, sizing for the screen, choosing a quality tier.
The model#
Games never touch OS Beroun or the page directly; they use FerretPlatform, picked by detectPlatform: BerounPlatform (OS), BrowserPlatform (localStorage under storageKey), HeadlessPlatform (tests, in memory, resize() and suspend() to simulate the host).
Steps#
- State:
loadState()(last saved ornull),saveState(obj). - Save in
onSuspend(fn); on OS Beroun the app is closed with about two seconds to save. - Screen:
screen()gives size, density andDeviceClass(console,phone,tablet,desktop); follow withonResize. Display.trackCamera(cam)keeps the field of view right (fovFor);renderScaletrades sharpness for speed;initialTierpicks the starting tier (the console is alwayslow);display.setTier(tier)at run time.- Lay the HUD out in
emfrom the UI scale.
Check afterwards#
Run headless with HeadlessPlatform: save, suspend(), reload, state is back; resize to a phone and a 4K screen, nothing is cut off.
What usually goes wrong#
- Relying on
beforeunloadto save instead ofonSuspend. - Pixel-sized HUD that is unreadable on the console or 4K.
- Requiring Pointer Lock or mouse look: not available on the console.
- Forgetting that physics tiers follow the same names as display tiers (see
ferret-physics-fx-tuning).
Files#
reference/platform.md— One interface over OS Beroun and the browser; screen, device class and quality tiers.reference/api-platform.md— every export of@ferret/platformwith signature and doc comment