Tilemap editor

Paint levels on a grid with built-in tiles or your own tileset, then export JSON or CSV along with Pygame code that loads and draws the map.

Updated

Tiles

Tile 1

Tileset

The image is cut into squares of the tile size above. Without one, the built-in set of 8 tiles is used.

Export

Pick a tile and paint. 0 means empty; tiles are numbered from 1.
On this page

How to use it#

  1. Set the map's columns, rows and tile size, then press Resize map. Existing tiles are kept where they fit.
  2. Pick a tile from the palette and paint by clicking or dragging. Right-click erases; fill floods an area.
  3. To use your own art, Import tileset image: it's cut into squares of the tile size, left to right and top to bottom.
  4. Export the map as JSON or CSV, the tiles as Tileset PNG, and copy the Pygame loader.
  5. Open JSON or CSV reloads a saved map to keep editing.

With the map focused, the arrow keys move a cursor and Space or Enter paints. The status bar shows the tile and pixel position under the pointer. Your map is saved in this browser automatically.

File formats#

CSV: one row of the map per line, tile IDs separated by commas. 0 means empty; the first tile in the tileset is 1.

Text
0,0,0,0,0
0,4,4,0,0
3,3,3,3,3
2,2,2,2,2

JSON: the same grid plus metadata:

JSON
{ "format": "pygame.net-tilemap", "version": 1, "tile_size": 32,
  "columns": 5, "rows": 4, "tileset": "tileset.png", "empty": 0,
  "data": [[0,0,0,0,0], [0,4,4,0,0], [3,3,3,3,3], [2,2,2,2,2]] }

Using the map in Pygame#

The copied loader provides load_tileset(), load_map(), draw_map() (with camera offsets) and solid_rects() for collisions. A minimal game loop using it:

Python
tiles = load_tileset("tileset.png")
level = load_map("map.csv")
walls = solid_rects(level, solid_ids={2, 3, 4})

while running:
    ...
    screen.fill("skyblue")
    draw_map(screen, level, tiles, camera_x, camera_y)

The tile maps tutorial explains pre-rendering and cameras, and the platformer tutorial shows collisions with tiles.

Built-in tiles#

The eight built-in tiles (grass, dirt, ground top, stone, water, sand, brick and coin) are drawn by the editor, so you can prototype immediately. Tileset PNG exports them for use in your game; they are free to use.

↑ ↓ to moveEnter to openEsc to close