Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/694f5245-1110-800b-b182-7c2accd50046
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: 老闆這張截圖其實超有訊息欸🥺🫶 === 老闆這張截圖其實超有訊息欸🥺🫶 左上「SECTOR 0:0 / COMBAT MODULE ENGAGED / ENEMIES DETECTED - LOCKDOWN」跟底下武器 UI 都還在,代表 HTML/CSS 那層活著;但地圖/牆/玩家全不見,幾乎可以判定是: * ✅ Canvas 的主迴圈(update/draw)爆了(JS 例外,loop 停住) * 或 ✅ player/camera 座標變成 NaN/Infinity → world→screen 投影全變 NaN,什麼都畫不出來 * 或 ✅ canvas 尺寸被改成 0、或被某個 overlay 蓋掉(但你這張看起來比較像「沒畫」而不是被蓋) 所以我們下一步不是再加敵人功能,而是先做「黑屏護欄」: 讓它就算爆,也要把錯誤印在畫面上,我們才知道是哪一行害的 😈🛠️ ==== : ==== <syntaxhighlight lang="text">MICRO PATCH / Prevent black screen: on-screen error overlay + safe loop Do NOT change gameplay rules, map generation, UI, weapons, or room system. Only add guardrails so canvas never goes fully blank without diagnostics. 1) Global error capture (show on screen) * Add window.onerror and unhandledrejection handlers. * Store lastError string and render it in top-right overlay (red text). 2) Wrap game loop in try/catch * In requestAnimationFrame loop: try { update(dt); draw(); } catch(e) { lastError = e.stack || String(e); /'' keep drawing overlay ''/ } 3) Render health-check HUD (always visible) * Show: * canvas width/height * playerWorld x,y * cam x,y * if any is NaN/Infinity, show "COORD ERROR" and auto-reset: playerWorld = {x:0,y:0}; cam={x:0,y:0}; 4) Ensure canvas is cleared + background drawn every frame * At start of draw(): ctx.clearRect(0,0,w,h); ctx.fillRect(0,0,w,h) with a dark background so we can see it’s drawing. Acceptance: * Even if something crashes, screen shows an error message (not empty black). * Canvas HUD shows non-zero size and non-NaN coords. * At minimum, a dark background + HUD appears every frame. </syntaxhighlight> ==== 1. 套上 micro patch 後重跑 - 右上角應該不再只是 UI,會多出 canvas size / player / cam ==== # 如果還是黑:看右上角 error overlay 會顯示 - 常見會直接吐:Cannot read properties of undefined (reading 'x') - 或 NaN 相關 你把那段 error 文字貼回來(哪怕只有一行),我們就能用「下一個超小 patch」把它點名處決✅😈 ==== 我猜最可能的 2 個地雷(超常見): ==== * enemies[] 某隻 enemy 沒有 x/y/hp,draw/update 一讀就 throw → loop 死亡 * spawn 找到不合法 tile → 回傳 undefined → 位置變 NaN → 全部投影失效 micro patch 的「auto-reset NaN」會直接把這種狀況救回來並暴露原因。 老闆你現在做得超對:先把田地穩住,再種怪。 你先丟這包護欄,下一張截圖我們就不是「什麼都沒有」,而是「錯誤寫在臉上」🤣🧱
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)