玩家入口测试 WASD 没反应,无法移动屏幕
1 小时前综合
编辑模式测试 WASD 可以移动屏幕,而且可以Q/E旋转地图
嗒:
关键发现!currentScene_ 在 EnterGame() 时设为 "game"(第2064行),但随后在预加载阶段变成 "loading"(第2733行)。预加载完成后,需要检查是否把它改回 "game"。
确认了!setupGameUI 函数结束时没有恢复 currentScene_ = "game"。
现在让我追踪完整的流程:
EnterGame() → currentScene_ = "game" ✅
beginPreloading() → currentScene_ = "loading" ← 改为 loading
预加载完成 → preloadState_ = nil → 调用 setupGameUI()
setupGameUI() → 设置 UI、创建 gameCanvas,但从未恢复 currentScene_ = "game" ❌
所以预加载之后 currentScene_ 永远停留在 "loading"!
回看 HandleKeyDown:
lua
复制
if currentScene_ == "loading" then
if key == KEY_ESCAPE then ... end
return -- ← 直接 return!所有非 ESC 键都被吞掉了!
end
以及 HandleUpdate:
lua
复制
elseif currentScene_ == "game" and gameCanvas_ then -- ← 永远不会进入这个分支!
gameCanvas_:UpdateInput(dt)
这就是根因! 预加载完成后 currentScene_ 仍然是 "loading",导致:
HandleKeyDown 中 Q/E/WASD 分支永远进不去
HandleUpdate 中 UpdateInput(dt) 永远不调用
所有键盘功能完全失效
而编辑器模式没有预加载流程,currentScene_ 始终是 "editor",所以一切正常。
让我看看是否还需要检查不走预加载的路径(某些情况下可能直接调用 setupGameUI)。


