How-to

levelsio 用 Claude Code 修复 BF1942 竖屏界面拉伸问题

Why we picked it

levelsio 用 Claude Code 改 BF1942 引擎,把竖屏拉伸的 HUD 按 2.9 倍比例缩回去,四步思路讲得很清楚。

开发者 levelsio 通过修改游戏引擎,解决了 Battlefield 1942(BF1942)在手机竖屏模式下界面被拉伸的问题。Claude Code 给出的方案分四步:先通过投影矩阵区分 3D 世界绘制与 HUD 平面绘制,再在 CPU 上预先计算每个 HUD 元素(票数、地图、弹药图标)的屏幕落点,随后按 2.9 倍的比例向最近的固定边缘收缩元素高度,使地图与图标保持对齐。计分板和加载图等大面板保留原有拉伸,菜单和加载界面的文字则围绕自身中心缩小,保证点击区域不偏移。

Original · Pieter Levels

Fixed the mobile stretched interface on portrait mode in BF1942 by modding the engine

Claude Code told me how it did it:

"1. Spotting the HUD: 3D world draws use a perspective projection, where far things look smaller. The HUD uses a flat one. I can tell them apart from the projection matrix the game sets before each draw.

2. Measuring each element: before drawing a HUD piece (the ticket count, the map, an ammo icon), I calculate on the CPU where its corners land on screen. That uses the same matrix math the graphics card would do.

3. Squeezing it back: I shrink its height by that 2.9× factor toward a fixed edge depending on where it sits. Things at the top move toward the top edge, things at the bottom toward the bottom edge, and things in the middle toward the center. Because everything in the same band moves together, the map and its icons stay lined up.

4. Leaving some things alone: big panels, like the scoreboard and loading photo, keep the old stretch so their layout isn't changed. On menu and loading screens, text shrinks around its own center so tap areas don't move."