Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

Rotating the phone made Pudding 50% faster

Pudding is a one-button runner. The jelly's speed lives in world units. We never changed that number when you rotated the phone. And yet portrait felt quicker than desktop, and a wide phone felt slower than both. The ph

Rotating the phone made Pudding 50% faster

Same world speed crossing three different view widths

Pudding is a one-button runner. The jelly's speed lives in world units. We never changed that number when you rotated the phone. And yet portrait felt quicker than desktop, and a wide phone felt slower than both.

The physics were fine. The camera was not.

Before and after: view width followed the screen, then locked at 256

The bug was the view width

Apparent speed β€” how fast the world crosses the screen β€” is just:

world units per second Γ· view width

If the logical view gets narrower, the same velocity eats more screen-widths per second. The jelly looks bigger. The kitchen scrolls harder. Nothing in the simulator moved faster.

That's what we had shipped:

  • 16:9 desktop: 320 dots wide
  • Phone portrait: 214 dots wide (we had zoomed in about 20% after players said mobile felt slow)
  • Phone landscape (844Γ—390): 390 dots wide, because wide windows grew the view up to 432

So at the same world speed, portrait crossed about 50% more screen-widths per second than 16:9 desktop (320 Γ· 214). Phone landscape went the other way: a wider view, a slower-feeling run.

Rotate the phone mid-run and the width jumped again, so the zoom β€” and the feel β€” popped in the middle of a jump.

The fix: one width, then scale to fit

We now lock the horizontal view at 256 dots on every layout. 16:9 is 256Γ—144, the same ratio as the old 320Γ—180. Taller than 16:9, we keep the width and grow the height (more sky, up to 800). Wider than 16:9, we keep 256Γ—144 and pillarbox the sides.

Diagram of a fixed 256-wide logical view scaled to fit 16:9, portrait, and wide windows

The sizing function is small. Physics never see it.

export const VIEW_W = 256;
export const BASE_H = 144; // 16:9, same ratio as the old 320Γ—180
export const MAX_H = 800;

export function viewSize(vw: number, vh: number) {
  if (!(vw > 0) || !(vh > 0)) return { w: VIEW_W, h: BASE_H };
  const aspect = vw / vh;
  if (aspect < VIEW_W / BASE_H) {
    // Taller than 16:9: keep width, grow height.
    return {
      w: VIEW_W,
      h: Math.max(BASE_H, Math.min(MAX_H, Math.round(VIEW_W / aspect))),
    };
  }
  // 16:9 or wider: keep 256Γ—144 and pillarbox the sides.
  return { w: VIEW_W, h: BASE_H };
}

During a run we also freeze W and H. A resize only changes the CSS stage, so the current view letterboxes or pillarboxes. Home, the result screen, and the next run start unlock and refit.

// Mid-run: don't change W/H. Only the CSS stage size changes.
if (!aspectLocked && (next.h !== H || next.w !== W)) {
  W = next.w;
  H = next.h;
  // rebuild buffers, nudge the camera…
}

Rotating mid-run letterboxes the locked 256Γ—144 view; the next run refits to a tall 256Γ—554

What we measured

We timed world displacement over about 3.85 seconds, early in a seeded run, and divided by view width.

Bar chart of apparent speed before vs after on desktop, portrait, and landscape

After the fix, desktop, portrait, and landscape measured 0.419, 0.428, and 0.433 screen-widths per second. That's effectively the same camera. The leftover gap is sampling noise: the runner is still accelerating, and the three windows started a meter or two apart (about 11–13m).

We didn't record the same timed samples on the old build. The before bars on the chart are therefore implied, not re-timed: the same world speeds divided by the old widths of 320, 214, and 390, which comes out to 0.335, 0.512, and 0.284. That is the whole bug. Collision, jumps, and distance were already in world units, and they stayed there.

A checklist you can reuse

  • If perceived speed should be stable, don't let logical view width follow the window's aspect ratio.
  • Pick one horizontal view width. Scale it to the window. Add letterbox or pillarbox bars, or grow the other axis β€” never a new width.
  • Freeze the view mid-session. Refit on menus and at the start of the next run, so a rotate doesn't zoom in the middle of a jump.
  • Measure apparent speed as world units per second Γ· view width (screen-widths/sec), not CSS pixels per second. Pixel speed changes with window size even when the camera is correct.
  • Keep simulation in world units. The camera is a view, not a physics step.

Try it

This is already live in the current itch build. Give it a run in any orientation.

Play Pudding Escape: Super Jelly β€” and see if you can beat 3,226m, GPT-6.2 Astra's record.

Originally posted on the Pudding devlog on itch.io.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.