通过修改引擎修复了《战地1942》竖屏模式下手机界面拉伸的问题,Claude Code 告诉我它是怎么做到的:“1. 定位 HUD:3D 世界……”

·

产品与工具 · 2026/11/05

作者通过修改《战地1942》引擎,修复了移动端竖屏模式下界面拉伸的问题。Claude Code 解释了其方法:通过投影矩阵区分 HUD 和 3D 世界,在 CPU 上计算 HUD 元素在屏幕上的位置,然后根据元素位置将其高度按 2.9 倍比例向固定边缘压缩,同时保持大面板和菜单文本不变。此外,@levelsio 将游戏移植到移动网页,Claude Code 构建了将 Direct3D 指令转换为 WebGL 的图形层,使游戏可在 iPhone 和 Android 浏览器上多人游玩。

本文展示了如何通过引擎修改解决移动端界面适配问题,并介绍了将经典游戏移植到网页的技术方案,对游戏开发和图形编程有参考价值。

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."

<hr />@levelsio: I managed to port Battlefield 1942 to mobile web too

So now it's playable as full multiplayer on iPhone and Android from their browser! 🤯

Claude Code built its own graphic layer that translates Direct3D (DirectX) instructions to WebGL, sitting between the game's machine code

在原站观看视频

资讯配图

资讯配图

阅读原文

参与讨论