Skill: Fix a runtime error
Diagnose and fix a BLIT386 game error using the local docs. Use this whenever the game crashes, shows a blank or black screen, throws an error in the...
Written for blit386 1.8.0. The rest of blit386.dev documents the newest engine, so an API you find there may be missing from a game pinned to 1.8.0.
Diagnose and fix a BLIT386 game error using the local docs.
When to use
Use when the game crashes, shows a blank screen, throws an error in the browser console, or behaves unexpectedly.
Steps
- Open
docs/when-something-breaks.mdfirst. It covers the most common beginner errors with concrete fixes. - On a blank screen: ensure
BT.paletteSet(palette)was called ininit()before any draw call. - If you see "Cannot read properties of undefined": you likely forgot
awaitbefore sprite or font load calls. - Note: 0 is not a valid palette index - slot 0 is always transparent; use slot 1 or higher.
- Check
AGENTS.mdfor correct engine API usage - getters have no(), methods do. - Post-process effects require WebGPU - confirm
BT.activeBackendis not'software'(the Canvas 2D fallback does not run effects). Keep starters free of post-process effects.
What to check
update()is for logic only;render()is for drawing only. Drawing inupdate()causes visual glitches.- If key or button taps feel randomly missed:
isKeyPressed/isKeyReleased/inputString/isPressed/isReleasedmust be read inupdate(). Reading them inrender()can miss the one-frame edge; seedocs/input.md. - All screen coordinates must be whole numbers (
Vector2i,Rect2i). Fractions cause off-by-one pixel issues. - A sprite that will not stretch into a
Rect2i, or an error about aRect2idestination: the stretch form ofBT.drawSpriteneeds an options object as the 4th argument ({}is enough), withscaleat1and nopivot(engine 1.8.0+). A palette fade at the wrong speed, or a slot set inrender()that snaps back: palette effects now step once perupdate(), so change slots inupdate()/init(). Both are indocs/when-something-breaks.md. - If you see
{{or}}in a file, a template placeholder was not substituted - this is a scaffolding bug, not a game bug. - After a save that breaks
init(), hot reload should leave the previous game running - fix the typo and save again (seedocs/hot-reload.md). If every tiny edit full-reloads the page, confirmvite.config.jshasplugins: [blit386()]and blit386 is 1.4.0+.
Skill: Draw shapes
Draw rectangles, lines, and single pixels and clear the screen using palette slots. Use whenever the user wants boxes, outlines, lines, dots, or a...
Skill: Keep it fast
Find and fix slow frames: stop making new objects every frame, batch sprites by sheet, skip what is off screen, and stay inside the engine's per-frame...