Bash.tv → GitHub → itch.io

Portrait and landscape handling for browser games on phones and tablets. Choosing an orientation per genre, supporting both with separate layouts (and a square layout for tablets), a "rotate your device" screen only on handheld devices (never desktops), pausing while it shows, locking landscape where Android allows it, the delayed size iOS reports right after rotating, safe areas that move with...

Download skill (.zip) Files on GitHub

Screen orientation

Pick per game

Orientation Good for
Portrait One-thumb games: endless runners, puzzle, card, idle, vertical shooters, visual novels
Landscape Two-thumb games: platformers, racing, twin-stick, most action, RTS
Both Turn-based, board games, sims: pick layouts per shape

Supporting both is best (no rotate screen at all). If the game truly needs one, show a rotate hint, but only on phones and tablets: a desktop window that’s tall must never be told to rotate.

assets/orientation.js

import { createOrientation, drawRotateHint, rotateOverlayCss } from "./orientation.js";
const orient = createOrientation({ want: "landscape", onChange: () => layoutUI(), onSettle: () => resize() });
orient.listen();                                         // resize + orientation events
loop: if (orient.wrong) { pause(); drawRotateHint(ctx, W, H, time, { want: "landscape", text: t("rotate") }); return; }
const L = orient.layout({ portrait: { hud: "top", controls: "bottom" }, landscape: { hud: "left", controls: "sides" }, square: {...} });
after a tap on Play, Android: await fs.enter(); await orient.lock();   // returns false where not allowed (most places)

HTML games can skip JavaScript: put <div id="rotate-hint">Rotate your device</div> in the page and add the CSS from rotateOverlayCss("landscape").

Rules

Tested

Node tests: portrait and landscape detection with and without media queries, the wrong-orientation state on handhelds only, change events and the settle re-check, lock refusing without throwing, layouts including square tablets, the CSS overlay and the canvas hint. The device lab (cross-browser-compatibility) shows the orientation live.

Pitfalls

A rotate screen on desktop, layouts that only work one way, measuring once at load, relying on orientation lock, and touch buttons under the notch after rotating.