walkenv tutorial

From a Tiled map to a playable walkenv game

Draw a level in Tiled, mark what blocks the player, and run it in the engine with an exact walkability mask. About 15 minutes.

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.

map.tmxlayers + spawn object assets/*.tsx + .pngtiles, solid=true walkenv engineparser → collision gridphysics, camera, renderer Screenshotwhat the player sees Walkability maskper-pixel walkable / blocked
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:

SettingValueWhy
OrientationOrthogonalThe engine draws a square grid.
Tile layer formatCSVThe only format the parser reads (Tiled's default).
Tile render orderRight DownDefault.
Map sizeFixed, e.g. 20 × 15 tilesInfinite maps are stored in chunks and aren't supported.
Tile sizeSame as your tileset, e.g. 16 × 16World 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

  1. Put the tileset image (PNG) in env/assets/. CC0 packs such as Kenney's work well; keep an ATTRIBUTION.md for anything CC-BY.
  2. Map → New Tileset…, type Based on Tileset Image, pick the PNG, tile size 16 × 16, margin 0, spacing 0.
  3. Save the tileset as env/assets/<name>.tsx (external tilesets can be shared between games).
NoteMargin and spacing must be 0, and "Collection of Images" tilesets aren't supported yet. If your pack has spacing between tiles, repack it into a plain grid first.

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)

  1. Open the .tsx in the tileset editor and select every tile that blocks movement (walls, water, trees, pipes…). Shift/Cmd-click to multi-select.
  2. In Custom Properties click +, add a bool property named solid and tick it.
  3. 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.

RuleA cell is blocked if any layer has a solid tile there, or the collision layer has any tile there. Tiled's per-tile collision shapes are ignored for now: a tile blocks completely or not at all.

7Paint the level

  • Use several tile layers, e.g. ground then decor. 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):

  1. Layer → New → Object Layer, pick Insert Point (I) and click.
  2. 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:

  1. 2DMap: set Source to map.tmx. The map appears in the viewport (press F to frame it, M for the mask).
  2. Agent: name it Player and drag it onto a walkable spot.
  3. Camera: set Behavior to Follow and TargetAgent to Player. Select Workspace and set CurrentCamera to it.
  4. 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, warn and script errors with line numbers.
  • Build exports builds/my_game/ with the runtime and a play.command you 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 / symptomFix
only CSV encoding is supportedMap → Map Properties → Tile Layer Format → CSV, then save.
layer '…' has wrong sizeThe map is infinite. Untick Infinite in Map Properties.
cannot load tileset / cannot load imageThe 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 editorThe 2DMap isn't under Workspace, or its Source is empty or wrong (the Console shows the load error).
Tiles look shifted or cutTileset margin/spacing isn't 0, or the tile size differs from the map's.
Player can't move at allThe agent overlaps a solid tile: drag it onto a walkable spot.
View stuck on the middle of the mapNo camera is active: set Workspace > CurrentCamera (or CurrentCamera = cam in Luau).
Camera doesn't followBehavior is Follow but TargetAgent isn't set.
Keys do nothing in PlayClick the game in the viewport first: it only gets the keyboard while focused.
Mask doesn't match the pictureA blocking tile is missing solid = true, or a decor tile has it by mistake.