Platformer camera, viewport size, and aspect ratios
cameraviewportaspect-ratioplatformermobilesafe-area
How much of the level a 2D platformer should show, how the camera should follow, and how to handle the many phone aspect ratios fairly. Numbers come from Run's research (2026-04) and its actual setup.
Viewport size
| Game | Base resolution | Tile | Tiles visible |
|---|---|---|---|
| Celeste | 320x180 | 8 px | 40 x 22.5 |
| Super Meat Boy | 1280x720 design | ~36 px | ~35 x 20 |
| Geometry Dash | auto-runner | ~30 px | 20-25 ahead, player at left 25% |
| SNES classic | 256x224 | 16 px | 16 x 14 |
- Run: fixed logical 1067x600 (16:9) via CameraComponent.withFixedResolution, 32 px tiles, |
|||
| so ~33 x 19 tiles. Generous, good for a speedrunner who needs to see ahead. | |||
| - The player sprite should fill about 3-5% of screen height (32/600 = 5.3%). | |||
| - Celeste's trick: very low logical resolution upscaled nearest-neighbor for crisp pixel art. |
Follow behavior
- Look-ahead in the direction of travel, scaled by speed (60-100 px at sprint). Lerp it; an instant offset jitters on direction changes (Run: lerp rate 3.0*dt).
- Dead zone: an invisible rect; the camera moves only when the player leaves it.
- Vertical is the hard problem: do not follow jumps in real time; re-baseline on landing and keep the player low on screen. Horizontal lerp fast (~20), vertical slow (~6).
- Clamp to level bounds; never show empty space.
- Per-region behavior (Donkey Kong Country): runner sections want a forward bias, exploration sections a centered view. A per-level zoom field (1.0-1.3) suits cramped levels; zooming out slightly at high speed gives more reaction time.
Aspect ratios
| Ratio | Devices | Result with fixed 16:9 |
|---|---|---|
| 16:9 | older phones | perfect fit |
| 20:9, 21:9 | modern phones, folded foldables | pillarbox |
| 4:3, 3:2 | tablets, iPad mini | letterbox (~20% of height on 4:3) |
| Strategies: (1) fixed 16:9 with bars: every player sees the same area, which keeps speedrun | ||
| competition fair (Run's choice); (2) expand width on wide screens: no bars but wide-screen | ||
| players see hazards earlier; (3) hybrid: fix height, let width grow to a cap (~1200 px). Fill | ||
| tablet letterbox bars with a themed gradient rather than black. Controls can live in the | ||
| pillarbox area. |
Safe areas and notches
- Render the world fullscreen behind notches; offset only interactive HUD with
MediaQuery.of(context).padding(Flutter'sSafeAreawidget is meant for app UI, not games).viewPaddingstill includes the notch when the keyboard shows;paddingis usually what you want. - Landscape iPhones have ~44 px left/right insets; Android gesture bars ~34 dp, iPhone home indicator ~20 dp; rounded corners up to ~40 px radius. Keep corner buttons 48 dp from both edges after the inset, plus 4-8 dp extra.
- Android targetSdk 35+ forces edge-to-edge; re-verify immersive mode
(
SystemUiMode.immersiveSticky, native Android only, not Flutter web) and re-apply it after resume, dialog dismissal and permission prompts.
HUD layout
Timer top center with the level name just below (eyes stay near the action); utility buttons top right; nothing tappable in the bottom third (controls zone). Auto-fade static info like the level name after ~2 s, fade HUD when the player passes beneath it, and show contextual items (coins, abilities) only when relevant.
See also
- Platformer movement feel (coyote time, jump buffering, wall jumps)
- Touch controls for mobile action and platformer games