Skill: Import a game made in a chat app
Move a one-file BLIT386 game made in a chat app (ChatGPT, Claude, Gemini) into this project, so you can keep working on the same game here. Use when the...
Written for blit386 1.9.2. The rest of blit386.dev documents the newest engine, so an API you find there may be missing from a game pinned to 1.9.2.
A chat app can write a whole BLIT386 game as one HTML file: a page, a canvas, and one <script type="module"> that
imports the engine from jsDelivr. This skill moves that game into a project, so it runs with npm run dev, hot
reloads, and can be tested with blit play. The game code itself does not change.
Rules
- Never edit, move, rename, or delete the user's HTML file. Read it and copy from it. If something goes wrong, the original is still there.
- Change only what the move needs: the import line, the page around the canvas, the title, and (step 4) a
canvasIDoption. Leave the game logic alone, even if you would write it differently. Improve it later, when the user asks.
Steps
-
Get a project. If there is none yet, make one next to the HTML file, with JavaScript (chat games are JavaScript, so no
--ts) and your own assistant's files (claude,cursor,codex,copilot,gemini,opencode,antigravity, orzed):npm create blit386@latest my-game -- --yes --agent claudeThe starter game it makes (Catcher) is replaced in step 3. Your assistant loads the project's hooks and docs server only from a session started in
my-game/, so ask the user to open a new session there (in Claude Code,/cdinto it) and continue from step 2 in that session. -
Find the game in the HTML file: the
<script type="module">block that imports fromhttps://cdn.jsdelivr.net/npm/blit386@X.Y.Z/dist/blit386.js. Note the versionX.Y.Z, the page<title>, and the canvas id (usuallyblit386-canvas). -
Replace all of
src/game.jswith the code between<script type="module">and</script>. Then change only the address in the import line to'blit386', and keep the list of names:// before import { bootstrap, BT, Color32, Rect2i, Vector2i, AudioClip, } from 'https://cdn.jsdelivr.net/npm/blit386@1.9.0/dist/blit386.js'; // after import { bootstrap, BT, Color32, Rect2i, Vector2i, AudioClip } from 'blit386';Keep
bootstrap(Game)at the bottom. It starts the game, the same as on the one-file page.Already in a TypeScript project (it has
src/game.ts, notsrc/game.js)? Put the code insrc/game.tsinstead. It runs as it is;npm run devdoes not check types, so add them later, when the user asks. -
Keep the project's own
index.html. It already has<canvas id="blit386-canvas">and CSS that scales the canvas crisply for any screen size, so the chat page's skeleton CSS (#wrap, the4/3sizes) is not needed. Change only:<title>: copy the title from the HTML file.- Extra page CSS or markup the game really uses (a font, a note under the canvas): copy it into
index.html. Skip the rules that only center and scale the canvas. - A different canvas id: keep
blit386-canvasinindex.html, and remove thecanvasIDoption the game passes tobootstrap, so both use the default.
-
Handle files that do not match the usual shape:
- Two or more inline scripts that belong to the game: put all their code into the game file from step 3, in page order, with one import line at the top.
- Other
https://imports or images and sounds loaded from the internet: keep them, and tell the user the game needs a connection for those. Offer to move the files intopublic/later. - No
class Gameor nobootstrap(...)call: stop and ask the user before rewriting anything. That is a different program, not a quick move.
-
Check the engine version. Compare the
X.Y.Zfrom step 2 with the installed engine: theversioninnode_modules/blit386/package.json, not the range inpackage.json.- Same version: nothing to do.
- The project's engine is newer (the usual case with a fresh project): keep it, so the guides and the
blittools match it, and tell the user in one line: "Your file used blit386 X.Y.Z; this project uses A.B.C." When the first number is the same, the game's code still works. If a name has changed, use themigrateskill. - The file's version is newer (an older project): the game may call something the installed engine does not have yet.
Run
npx blit upgradebefore step 7. It moves the project to the latest engine. On a project with no git commit yet it first asks "Upgrade anyway?", so commit first.
-
Run it and play it. Start the game with
npm run dev(ornpx blit run) and check that it looks and plays like the HTML file did, with no errors in the browser console. Then play-test it with thetest-the-gameskill, for examplenpx blit play wait:1500 hold:ArrowLeft:500 shot. A chat game has notestState()hook, sostateprints onlyticksuntil you add one (theuse-dev-modeskill shows how). In the project,window.BTworks in the browser console during development, which the one-file version did not have. -
Suggest a first commit, so the imported game is a clean starting point before any new changes.
Notes
- Need the other direction, a project back into one HTML file? That is
blit bundle --single; see theshare-the-gameskill anddocs/shipping-to-a-compo.md. - Everything the game used from the chat prompt (palette, drawing, input, sound) is the same API in the project. The other skills in this folder show what comes next: sprites, hot reload, a loading screen, more sounds.
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...
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...