旋轉手機令 Pudding 的體感速度快 50%
Rotating the phone made Pudding 50% faster
Pudding 將不同螢幕方向的水平視野寬度固定為 256 dots,修正旋轉手機時體感速度不一的問題,遊戲物理速度則維持不變。修正前,直向手機的畫面速度比 16:9 桌面快約 50%;修正後,桌面、直向及橫向畫面測得每秒 0.419、0.428 及 0.433 個螢幕寬度。修正已於目前的 itch 版本推出。
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.
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.
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…
}
What we measured
We timed world displacement over about 3.85 seconds, early in a seeded run, and divided by view width.
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.
來源:DEV Community · dev.to




