1How it fits together
A walkenv game is one folder. Tiled produces the map; the engine reads it, works out which cells block movement, and renders two images every frame from the same camera.
env/
├── assets/ # shared tilesets (.tsx + .png)
└── games/my_game/
├── map.tmx # made in Tiled
├── scene.json # the object tree, made in the walkenv editor
├── game.luau # game logic (a Script object in the tree)
└── config.json # screen, tile size, colours, perspective
2Install Tiled
Download Tiled from mapeditor.org (free; version 1.10 or newer), or with Homebrew:
brew install --cask tiled
3Create the game folder
Copy an existing game as a starting point. Use meadow_topdown for a top-down game or flappy_sideview for a side-view one.
cd ~/Documents/ML-Research/env
cp -R games/meadow_topdown games/my_game
rm games/my_game/map.tmx # you'll make a new one (keep the name map.tmx)
4Create the map
In Tiled choose File → New → New Map… and use these settings:
| Setting | Value | Why |
|---|---|---|
| Orientation | Orthogonal | The engine draws a square grid. |
| Tile layer format | CSV | The only format the parser reads (Tiled's default). |
| Tile render order | Right Down | Default. |
| Map size | Fixed, e.g. 20 × 15 tiles | Infinite maps are stored in chunks and aren't supported. |
| Tile size | Same as your tileset, e.g. 16 × 16 | World units are native tile pixels. |
Save it straight away as games/my_game/map.tmx, so Tiled writes the tileset path relative to that folder.
5Add a tileset
- Put the tileset image (PNG) in
env/assets/. CC0 packs such as Kenney's work well; keep anATTRIBUTION.mdfor anything CC-BY. - Map → New Tileset…, type Based on Tileset Image, pick the PNG, tile size 16 × 16, margin 0, spacing 0.
- Save the tileset as
env/assets/<name>.tsx(external tilesets can be shared between games).
6Mark blocking tiles
This is what becomes the ground truth. There are two ways; you can mix them.
Option A: a solid property on tiles (recommended)
- Open the
.tsxin the tileset editor and select every tile that blocks movement (walls, water, trees, pipes…). Shift/Cmd-click to multi-select. - In Custom Properties click +, add a bool property named
solidand tick it. - Save the tileset. Every map using it now knows which tiles block.
Option B: a collision layer
Add a tile layer, give it a bool property collision = true, and paint any tile wherever the player can't go. You can hide the layer (eye icon): it still counts for collision but isn't drawn. Useful for invisible walls.
7Paint the level
- Use several tile layers, e.g.
groundthendecor. They're drawn bottom to top in the order shown in Tiled. - B stamp brush, F bucket fill, E eraser, R rectangle select.
- Top-down: close the map with a solid border, or the player can walk off the edge (outside the map counts as blocked, so they'll just stop).
- Side-view: give the player a floor; leave gaps in obstacles that the player can actually fit through.
8Add named points (optional)
Agents and cameras are placed in the editor, so the map doesn't need a spawn point. Named points are still handy for scripts (respawn spots, goals):
- Layer → New → Object Layer, pick Insert Point (I) and click.
- Set the object's Name, e.g.
spawn, and save the map.
Read it in Luau with workspace.Map:GetPoint("spawn") (world position, already offset by the 2DMap's position).
9Set up the scene in the editor
Open the editor (./build/walkenv_editor or play_editor.command) and pick your game in the top bar. In the Explorer, right-click Workspace > Insert:
- 2DMap: set Source to
map.tmx. The map appears in the viewport (press F to frame it, M for the mask). - Agent: name it
Playerand drag it onto a walkable spot. - Camera: set Behavior to Follow and TargetAgent to Player. Select Workspace and set CurrentCamera to it.
- Script: set Source to
game.luau.
Save with Ctrl/Cmd+S (writes scene.json). Anything under Storage is kept but not simulated.
game.luau
--!strict
local player = workspace:FindFirstChild("Player") :: Agent
Game.Update:Connect(function(dt: number)
if player.IsDestroyed then return end
local s = 60 * dt
if Input:IsDown(Enum.Action.Left) then player:Move(-s, 0) end
if Input:IsDown(Enum.Action.Right) then player:Move(s, 0) end
if Input:IsDown(Enum.Action.Up) then player:Move(0, -s) end
if Input:IsDown(Enum.Action.Down) then player:Move(0, s) end
end)
Other signals: Game.Init, Game.LateUpdate (after physics), Input.ActionPressed, Input.ActionReleased, Input.KeyDown. Create objects at runtime with Instance.new("Agent", workspace). For autocomplete, point luau-lsp at env/types/walkenv.d.luau (see the README).
10Play and build
- Play (F5) runs the game in the viewport. Click the game to give it the keyboard. Stop restores the scene as it was.
- The Console shows
print,warnand script errors with line numbers. - Build exports
builds/my_game/with the runtime and aplay.commandyou can double-click.
Without the editor: ./build/walkenv_run games/my_game (M toggles the mask, Esc quits).
11Use it from Python
import sys; sys.path.insert(0, "build")
import walkenv
env = walkenv.Env("games/my_game", {"colors": {"hue_shift": 60}})
obs = env.reset()
obs = env.step(walkenv.RIGHT)
player = obs["info"]["agents"][0] # one dict per agent
print(obs["rgb"].shape, obs["mask"].shape, player["blocked"])
shot = env.render_at(120, 90, rotation=30) # centre x, y + rotation
Python loads the same scene.json; the module is built by default (-DWALKENV_PYTHON=ON).
- Map is fixed-size, orthogonal, CSV
- Tileset has margin 0 / spacing 0 and blocking tiles have
solid= true - Workspace has a 2DMap (Source set), an Agent on a walkable tile, a Camera set as CurrentCamera and a Script
- The scene is saved (no
*next to the game name in the top bar)
12Troubleshooting
| Message / symptom | Fix |
|---|---|
only CSV encoding is supported | Map → Map Properties → Tile Layer Format → CSV, then save. |
layer '…' has wrong size | The map is infinite. Untick Infinite in Map Properties. |
cannot load tileset / cannot load image | The path in the .tmx/.tsx is wrong. Re-add the tileset after saving the map in its game folder. |
tileset without image | "Collection of Images" tileset. Use one based on a single tileset image. |
| Map doesn't appear in the editor | The 2DMap isn't under Workspace, or its Source is empty or wrong (the Console shows the load error). |
| Tiles look shifted or cut | Tileset margin/spacing isn't 0, or the tile size differs from the map's. |
| Player can't move at all | The agent overlaps a solid tile: drag it onto a walkable spot. |
| View stuck on the middle of the map | No camera is active: set Workspace > CurrentCamera (or CurrentCamera = cam in Luau). |
| Camera doesn't follow | Behavior is Follow but TargetAgent isn't set. |
| Keys do nothing in Play | Click the game in the viewport first: it only gets the keyboard while focused. |
| Mask doesn't match the picture | A blocking tile is missing solid = true, or a decor tile has it by mistake. |