Level Editor Lite
Last reviewed
IntermediateWhat you'll learn
~60 min- Build a browser-based tile placement editor with React and a canvas grid
- Implement a tile palette with ground, wall, platform, hazard, spawn, and exit types
- Export level layouts as JSON that Phaser can load directly
- Add layer toggling for background and foreground elements
What you’re building
Up to this point, every enemy position, platform edge, and pickup location in your prototypes has been hardcoded as pixel coordinates typed by hand or generated by the AI. That works for a single test room. It does not work for designing an actual game level where you want to place 50 tiles, playtest, move 12 of them, add a hazard pit, and re-export — all before lunch.
Professional studios use level editors. Tiled, LDtk, Unity’s built-in scene editor — they all do the same fundamental thing: let you paint content onto a grid and export it as data. You are going to build a lightweight version of this. Not because you need every feature of Tiled, but because building your own editor means the output format matches your Phaser scene loader exactly, with zero conversion steps.
BloodRayne’s levels were a mix of platforming corridors, combat arenas, and vertical climbing sections. Your editor will let you design all of these by painting tiles: ground for walkable surfaces, walls for boundaries, platforms for vertical sections, hazards for environmental danger, spawn points for enemies, and exit triggers for level transitions.
Forty-five minutes from now you will have a browser-based tool where you click to place tiles on a grid, pick from a color-coded palette, switch between background and foreground layers, resize the grid, erase mistakes, and export the whole layout as JSON that your Phaser game can import directly.
Canvas grid + palette selection + click-to-place + JSON serialization. This pattern shows up everywhere: floor plan editors, dashboard layout builders, form designers, pixel art tools. Any application where humans need to visually arrange elements on a grid and export the arrangement as structured data.
The showcase
Here is the complete tool:
- Canvas grid: Configurable grid (default 25x19 tiles at 32px each = 800x608 viewport). Grid lines visible. Click any cell to place the selected tile type.
- Tile palette: Sidebar with 6 tile types, each a colored button with label:
- Ground (#4a5568, gray) — walkable floor
- Wall (#1e293b, dark blue-gray) — impassable boundary
- Platform (#8B5CF6, purple) — one-way platform the player can jump through from below
- Hazard (#ef4444, red) — kills or damages on contact (spikes, fire pits)
- Spawn (#f59e0b, yellow) — enemy spawn point (one per enemy)
- Exit (#22c55e, green) — level transition trigger
- Eraser mode: Click the eraser tool or press E to switch to eraser. Click a tile to remove it.
- Layer toggle: Two layers — Background (floor, walls) and Foreground (platforms, hazards, spawns, exits). Toggle visibility of each layer to work on one at a time.
- Grid size selector: Dropdown to change grid dimensions (20x15, 25x19, 30x23, 40x30). Changing size clears the grid with a confirmation prompt.
- JSON export: Button that generates a JSON object with grid dimensions, tile size, and a 2D array of tile types per layer. Copy to clipboard or download as
.jsonfile. - JSON import: Button to load a previously exported JSON file and render it on the grid for editing.
- Undo: Ctrl+Z undoes the last tile placement (keeps a history stack of 50 actions).
Before you start
If your AI tool is open from the previous lesson, leave it (/exit, or Ctrl+D in Antigravity) so you are back at your terminal prompt. Create a folder for this editor and step into it:
mkdir -p ~/retro-remake/17-level-editor-lite && cd ~/retro-remake/17-level-editor-liteIn Windows PowerShell, run mkdir ~/retro-remake/17-level-editor-lite; cd ~/retro-remake/17-level-editor-lite. In a desktop agent app, open ~/retro-remake/17-level-editor-lite as your workspace folder. Then start your AI tool the way Workbench Setup showed.
Switch to plan mode
Switch into Plan mode (Shift+Tab, /plan, or the mode picker) so your agent clarifies the tile palette, layers, canvas interactions, and Phaser JSON export schema before generating files.
The conversation
Each message below is an example. Say it in your own words.
Say what you want
Ask for a browser-based tile level editor that exports level data for your game:
Build a browser-based tile level editor where I can paint level layouts on a grid with a color-coded palette, toggle layers, and export JSON for my game. Ask me what you need first.Answer its questions
Your agent will ask about the tile types, layer system, grid painting controls, grid sizing, and JSON export format:
| If it asks | You might say |
|---|---|
| Which tile types and shortcuts should the palette include? | Six tiles (1-6): Ground and Wall on background; Platform, Hazard, Spawn, and Exit on foreground, plus E for Eraser. |
| How should the grid painting and layers work? | Click or drag to paint, right-click to erase, hover preview, and filter All, Background, or Foreground (dimming inactive to 20%). |
| What toolbar controls do you want? | Grid size presets (20x15, 25x19, 30x23, 40x30), layer toggle, 50-step Ctrl+Z undo, Clear Grid, Export JSON, and Import JSON. |
| What should the exported level file contain? | Grid dimensions, tile size, separate background and foreground grids, plus flat coordinate lists for enemy spawns and level exits. |
| How should Export deliver the JSON? | Copy the JSON to the clipboard, download level-export.json, and show a brief toast notification. |
Read the plan
Before approving the build, check the agent’s plan for these four details:
- Six color-coded tile types across two layers (
src/tileTypes.js):ground(#4a5568) andwall(#1e293b) onbackground;platform(#8B5CF6),hazard(#ef4444),spawn(#f59e0b, marked with"S"), andexit(#22c55e, marked with"E") onforeground, selectable via keys1-6andEfor eraser. - Smooth canvas interaction (
src/Canvas.jsx): snaps mouse coordinates withMath.floor(offset / tileSize)(default 25x19 grid at 32px tiles), supports continuous drag-painting, right-click erasing, hover preview, and renders the inactive layer at 20% opacity when filtering bybackgroundorforeground. - 50-step undo and grid resizing (
src/useEditorState.js+src/Toolbar.jsx): records{ layer, x, y, previousTile }on an undo stack (up to 50 steps, bound toCtrl+Z) and confirms before clearing the grid on dimension changes (20x15,25x19,30x23,40x30). - Phaser-ready JSON export and import (
src/exportLevel.js+src/importLevel.js): exports{ meta, layers: { background, foreground }, spawns, exits }(extracting spawn and exit coordinates into flat arrays for Phaser entity creation) and re-imports.jsonfiles back onto the canvas.
If the plan exports only a single flat layer or omits the extracted spawns and exits arrays, steer it before approving:
Keep the background and foreground layers separate in the exported JSON, and also include flat coordinate lists of enemy spawns and exits for the game loader.Once the plan covers all four points, approve it and let your agent build the editor. After painting a level, exporting level-export.json, and importing it back in your browser, ask your agent to save a Git checkpoint.
The level editor is not part of the game the player sees. It is your content creation pipeline. You use it to design levels, export JSON, and feed that JSON into the Phaser game. Separating the editor from the game means you can iterate on level design without touching game code.
What you get
After generation, the project folder structure looks like this:
17-level-editor-lite/ package.json index.html src/ main.jsx App.jsx Canvas.jsx Palette.jsx Toolbar.jsx tileTypes.js exportLevel.js importLevel.js useEditorState.jsFire it up
Ask your agent to install what is needed, start the local server, and open the editor:
Install the packages, start the local server, and open the tile level editor in my browser.Or run it from a terminal:
cd ~/retro-remake/17-level-editor-litenpm installnpm run devOpen the URL. You should see a dark-themed editor with a grid in the center, a tile palette on the left, and a toolbar at the top. The grid is empty. Ground is selected by default.
Click anywhere on the grid to place a gray ground tile. Click and drag to paint a floor. Press 4 to switch to hazard, paint some red danger zones. Press 5 for spawn points, place a few yellow enemy markers. Press 6 for an exit, place a green tile at the right edge. Click “Export JSON” and check your clipboard — that is a complete level definition your Phaser game can load.
If something is off
| Problem | Follow-up prompt |
|---|---|
| Canvas does not respond to clicks | Clicking on the grid does not place any tiles. Make sure clicking any cell snaps to the hovered tile coordinate, places the currently selected tile on its layer, and redraws the grid immediately. |
| Click-and-drag paints only the first tile | I can place one tile per click, but holding the mouse button and dragging across the grid does not paint a continuous line of tiles. Let me click and drag to paint or right-click and drag to erase. |
| Exported JSON has wrong dimensions | The exported JSON file shows empty layers or zero dimensions instead of what I painted on screen. Make sure the export reads the current grid size and both painted layers accurately. |
| Layer toggle does not change opacity | Switching between All, Background, and Foreground views does not dim the inactive layer. When I filter to Background or Foreground, fade the other layer to 20% opacity so I can still see it for alignment. |
Deep dive
This editor is a content creation tool, and understanding its data flow clarifies why it is structured this way.
The grid is two 2D arrays. Background layer holds ground and wall tiles. Foreground layer holds platforms, hazards, spawns, and exits. This separation matters because in Phaser, background tiles are static collision geometry and foreground objects are interactive entities with behaviors. Keeping them in separate arrays means the game loader can process them independently.
Click-to-place with grid snapping is the core interaction. The mouse position is divided by tile size and floored to get grid coordinates. This means every tile lands perfectly aligned, even with sloppy clicks. Drag-painting uses the same math on mouse-move events, giving you the “paint” feel that makes filling large areas fast.
The export format is designed for Phaser consumption. The JSON includes raw 2D arrays (for tilemap rendering) plus extracted spawns and exits arrays (for entity creation). A Phaser scene loader reads the background array to create static collision tiles, reads the foreground array to create platforms and hazards with physics, and iterates the spawns array to instantiate enemies at those positions. No format conversion. No intermediate processing.
Undo uses a simple stack pattern. Every tile placement pushes the previous state of that cell onto the stack. Undo pops the most recent entry and restores it. This is the same pattern used in text editors, drawing tools, and form builders. Fifty entries is enough for practical editing without consuming significant memory.
🔍Loading exported levels in Phaserclick to expand
Once you export a level JSON from this editor, loading it in Phaser looks like this (the AI generates this code when you integrate everything in the Playable Demo Assembly):
REFERENCE CODE Phaser scene loader consuming levels/chapter1.json open reference hide reference Reference example of how your agent wires the JSON level file in code; you do not write this JavaScript yourself.
// In preload():this.load.json('chapter1', 'levels/chapter1.json');
// In create():const levelData = this.cache.json.get('chapter1');const { gridWidth, gridHeight, tileSize } = levelData.meta;
// Create background tiles as static physics bodieslevelData.layers.background.forEach((row, y) => { row.forEach((tile, x) => { if (tile === 'ground' || tile === 'wall') { // 'ground' and 'wall' must be loaded or generated textures first (draw a square with a Graphics object and call generateTexture) const block = this.physics.add.staticImage( x * tileSize + tileSize/2, y * tileSize + tileSize/2, tile ); } });});
// Spawn enemies at marked positionslevelData.spawns.forEach(spawn => { this.createEnemy(spawn.x * tileSize, spawn.y * tileSize);});The editor creates the data. The game consumes it. Two separate tools, one shared format.
Customize it
Add a tile name editor
Add a level name text input in the top toolbar that saves the level's name in the exported JSON (defaulting to untitled) and repopulates when importing a level file.Add entity properties
When I select a placed spawn or exit tile, show a small popover to pick the enemy archetype (basic, fast, heavy, boss) or target level name and include it in the export.Add a playtest preview
Add a Preview button in the toolbar that opens a playable test modal loading the current grid so I can test WASD platforming, wall collisions, hazard damage, and the exit trigger.Try it yourself
- Walk through the plan-mode conversation above and let your agent build the project.
- Ask your agent to start the editor (or run
npm install && npm run dev) and open it in your browser. - Design a simple combat arena: ground floor across the bottom, walls on the sides, a few platforms at different heights, hazards below the platforms, 3-4 enemy spawns, and an exit at the top-right.
- Toggle between Background and Foreground views to see how the layers separate.
- Export the JSON. Open it in a text editor and verify it contains your level layout.
- Clear the grid, import the JSON you just exported. The level should reconstruct exactly as you designed it.
- Now design a second level — a vertical climbing section with narrow platforms and hazards. Export that too. You now have two levels ready for integration.
Key takeaways
- Visual editors eliminate coordinate guessing. Placing tiles by clicking is orders of magnitude faster and more accurate than typing
{x: 384, y: 256}in code. - JSON export is the bridge to Phaser. The editor’s output format is designed so the game loader can consume it directly with no conversion step.
- Two layers match Phaser’s architecture. Background for static collision, foreground for interactive entities. Separate arrays, separate processing.
- The editor is a content pipeline tool. It does not ship with the game. It runs separately, produces data files, and those files drive the game. Content and engine are independent.
- Undo makes experimentation safe. Try a layout, hate it, Ctrl+Z. The cost of trying something is zero.
The level editor shifts your work from writing code to making design decisions. Where should the enemies be? How high should the platforms be? Where does the player enter and exit? These are game design questions, not programming questions. The tool lets you answer them visually.
What’s next
You can design levels, but how do you know they are actually playable? An enemy might be placed inside a wall. A jump might be too far for the player’s physics. A room might be trivially easy or impossibly hard. In the next lesson you will build a game test harness — an automated test runner that scripts collision checks, spawn verification, and balance scenarios, then generates an HTML report with pass/fail results. QA without a QA team.