Bash.tv → GitHub → itch.io

Make a browser game fit every screen. Phones in portrait and landscape, tablets, desktops, ultrawide, the Bash preview iframe and itch.io embeds. Picking a scaling strategy (letterbox, expand, integer pixel scaling), sharp rendering with devicePixelRatio, safe areas and notches, the mobile browser toolbar (dvh), resize and orientation handling, readable UI sizes, and fullscreen. Use for "it's c...

Download skill (.zip) Files on GitHub

Responsive game design

1. Choose a scaling strategy

Strategy What happens Use for
Letterbox (fit) Fixed game size (e.g. 960×540) scaled to fit; bars fill the rest Most games. Simple, fair (everyone sees the same area)
Expand Fixed minimum area; extra space shows more world Exploration, top-down, idle, strategy. Looks native on every screen
Integer pixel scaling Scale by 1×, 2×, 3× only; nearest-neighbor Pixel art (no shimmering or uneven pixels)
Fully fluid (DOM/CSS) Layout reflows Card, word, quiz, UI-heavy games

Expand code: keep the shorter side fixed in game units and let the other grow.

function resize() {
  const vw = innerWidth, vh = innerHeight, dpr = Math.min(devicePixelRatio || 1, 2);
  const BASE = 540;                                            // game units on the short side
  const scale = Math.min(vw, vh) / BASE;
  view.w = vw / scale; view.h = vh / scale;                    // visible world size in game units
  canvas.width = Math.round(vw * dpr); canvas.height = Math.round(vh * dpr);
  canvas.style.width = vw + "px"; canvas.style.height = vh + "px";
  ctx.setTransform(scale * dpr, 0, 0, scale * dpr, 0, 0);
  view.scale = scale;                                          // pointer: gameX = clientX / scale
}
addEventListener("resize", resize); screen.orientation?.addEventListener("change", resize); resize();

Letterbox is in the game-scaffolding template (src/core/screen.js).

2. Sharp, not blurry

3. The page around the game

html, body { margin: 0; height: 100%; overflow: hidden; background: #000; }
#game { position: fixed; inset: 0; width: 100vw; height: 100dvh; }   /* dvh: excludes the mobile toolbar */
.hud { padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }

4. UI that adapts

5. Fullscreen (optional)

A button that calls document.documentElement.requestFullscreen?.() inside a click. iPhone Safari has no element fullscreen. Don’t rely on it, and hide the button if !document.fullscreenEnabled.

Test matrix

set_preview_viewport phone portrait, phone landscape, tablet, desktop → look_at_preview each. Check: nothing cut off, text readable, controls reachable, no scrollbars, sharp edges, pointer hits land where tapped. Restore the viewport after.