Skip to main content

Tilemap editor

The tilemap editor paints tilemaps: a grid where each cell holds a tile, a square cut from an image of the project, the tileset. Each cell can also hold a cell value: a number you don't see that says what the cell is (floor, wall, spikes…).

It edits the .map files in the Maps folder. When you compile, the IDE turns them into the .gmap files that the GridMap module reads. The scene editor uses them for the tile layers of a room and for its collision map.

There are four ways to open it:

  • New TileMap, in the explorer menu (right-click) or on its button bar. It asks for a name, creates the .map and opens it. It goes into Maps, or into the folder you have selected in the explorer.
  • Double-click a .map in the explorer.
  • Edit tilemap..., on a tile layer in the scene editor: it opens that layer's map.
  • Home › View › TileMap, on the ribbon: it shows the editor. If no map is open, it gives you one with no file; when you save it, it asks for a name and creates it in Maps.

The editor holds one map at a time. If you open another one and there are unsaved changes, it first asks whether to save them.

The tilemap editor with JaruQuest's overworld map and its cell values showing

A walkthrough​

A map with floor and walls that collides in a room.

  1. Create the map. In the explorer, right-click Maps › New TileMap. Type a name, for example Level1, and accept: the IDE creates Maps/Level1.map and opens it. A new map is 20 × 15 tiles of 16 × 16 pixels, of type Tiles Only, with no tileset. If the editor had another map open, the new one gets that map's size, tile, type and tileset.
  2. Pick the tileset. In the Tileset panel, open Image and pick the image with the tiles. In Tile Size, enter the width and height of one tile, in pixels. The Tile Palette on the left shows the image cut into tiles.
  3. Paint. Click a tile in the palette (it gets a yellow frame) and paint on the map with Brush, one click at a time or dragging. The right button erases. For a row of floor, use Line; for a block, Rect.
  4. Mark what is solid. In the Mode panel, set Tilemap Type to Tiles + Cell Values and Active Layer to Cell Values. In Defined Values, click 1: Wall and paint over the floor and the walls: those cells turn hatched red, with a 1.
  5. Save with Save. While there are unsaved changes, the button reads Save ●.
  6. Try it in a room. In the scene editor, put the map on a tile layer of the room. In the Room tab, pick it as the Collision map. Solid values already holds a 1: cells with value 1 are solid. Press Play. Layers and The room and the game tell you more. If your game is written in code, see "From code" below.

Tools​

The tools paint on the active layer (Active Layer): the tile picked in the palette or the value picked in Defined Values. They have no keys.

ButtonLeft buttonRight button
BrushPaints each cell it goes over, one click at a time or dragging.Erases, the same way.
EraserErases: the cell is left with no tile, or with value 0.Erases.
FillFills the area of the clicked cell: every cell joined to it by a side, not diagonally, that has its same tile (or its same value).Erases the clicked cell.
RectDrag from one corner to the other and let go: it paints the rectangle, filled.Erases the rectangle.
LineDrag from one end to the other and let go: it paints the line of cells.Erases the line.

While you drag Rect or Line, the cells about to change get a frame: yellow if they will be painted, red if they will be erased. Fill on an empty cell fills every empty cell that touches it: handy to paint the background in one go.

The rest of the bar:

  • Undo and Redo undo and redo. Each stroke, from press to release, is one step; changing the map size is another. They keep up to 100 steps and start over when you open another map. They only undo painting and the size: not the tileset, the tile size, the map type or the defined values.
  • Resize Map applies the size in Size (Map panel).
  • Extract Tiles takes the loose tiles of an image into a new tileset (Tileset panel).
  • - and + zoom the map out and in, from 25 % to 400 %. The zoom shows between them.
  • Save saves the .map.
  • Generate Tileset saves an image of the whole map (Tileset panel).
  • Close closes the map and hides the editor. If there are unsaved changes, it asks first.

Panels and options​

Tileset​

The tileset is an image of the project, from any folder: import it with Import Image in the explorer or draw it in the image editor.

  • Image: the tileset image. The map stores which one it is, and the scene editor uses that same one on the tile layer.
  • Tile Size: the width and height of a tile, in pixels, from 8 to 128.

The Tile Palette, on the left, shows the image cut into tiles. Click a tile to pick it. If the image is not an exact number of tiles, the leftover on the right or at the bottom is hatched in orange and can't be picked. When you pick the image, the palette zooms in whole steps, up to ×4, to fill the width of the panel; Ctrl + mouse wheel zooms it in or out.

Tiles are numbered from 0, left to right and top to bottom. In an image 8 tiles wide, 0 is the top-left one and 8 the first one of the second row. Each cell stores that number: if you change Tile Size or the image once the map is painted, the numbers stay the same, but they point to other parts of the image.

255 tiles at most

In the game each cell is one byte, and 255 means "empty": a map can only use tiles 0 to 254. The editor lets you paint the ones beyond that, but when you compile the IDE stops with the error "tiles have index > 254".

For the tileset to reach the game, its image needs Include in Build on in the image editor. When you compile, the IDE exports it like the other images, into Build/flash, with the same path and as BMP: Images/Tiles.png ends up as Build/flash/Images/Tiles.bmp.

Extract Tiles​

It takes the tiles of an image where they are loose, separated by a background color (for example, a sheet with a margin between tiles), into a new tileset.

  1. Pick the image in Image and enter the size of one tile in Tile Size.
  2. Pick the background color: click the color box at the end of the Visualization panel, then a background pixel in the palette. Right-clicking the palette leaves it as it was. Until you pick another, it is black.
  3. Press Extract Tiles.

The editor looks for every patch of pixels that are not the background color and keeps the ones exactly one tile in size. It lays them out in rows of 16, in the order they appear in the image (top to bottom and left to right), and saves them as Images/<image>_extracted_<width>x<height>.png. The new image joins the project and becomes the map's tileset.

  • A tile with a border in the background color, or two tiles touching, are not exactly one tile in size: they are left out.
  • The new image joins with Include in Build on: when you compile, it reaches the game.
  • Do it before painting: in the new tileset, each number is another tile.

Generate Tileset​

Despite its name, it doesn't make a tileset: it saves a PNG image of the whole map, each cell painted with its tile and transparent where there is no tile. It is the map's size in pixels: a map of 20 × 15 tiles of 16 × 16 gives a 320 × 240 image. It asks where to save it and doesn't add it to the project; if you want it there, import it with Import Image.

Map​

Size (tiles x tiles) is the width and height of the map in tiles, from 1 to 256. It applies when you press Resize Map or leave the box. The map grows or shrinks on the right and at the bottom: the top-left part stays where it is. If shrinking loses something painted, it asks first, and Undo brings it back.

Mode​

A map has two layers of the same size: the tiles layer, which is what you see, and the cell values layer, which says what each cell is. Tilemap Type says which ones it uses:

  • Tiles Only: only tiles. The Cell Values panel and Show Cell Values are turned off.
  • Tiles + Cell Values: both layers.
  • Cell Values Only: only cell values. The map doesn't paint the tiles.

Active Layer says which layer the tools paint on: Tiles or Cell Values. You can only change it with Tiles + Cell Values; with the other two types, the layer is the only one there is.

Changing the type leaves a layer out when you save

The .map only stores the layers of its type. If you switch a map to Tiles Only and save it, the file loses its cell values; with Cell Values Only, its tiles. To get them back, switch back to the previous type and save again before you close the map.

Cell Values​

A cell value is a number from 0 to 255 that each cell holds, apart from its tile. It isn't seen in the game: your code or the room's collision reads it. 0 means "nothing": the editor doesn't paint it, and Eraser sets cells to 0.

  • Defined Values: this map's named values, as ID: name. Click one to paint with it: Painting says which one Brush paints.
  • ID, Name and Color: the number, name and color of the value you are editing. Clicking the Color box opens the color picker. Picking a value in the list fills these boxes with its data.
  • Add/Edit: if the ID is already in the list, it changes its name and color; if not, it adds it and picks it for painting.
  • Remove: removes the picked value from the list. Cells that hold it keep their number. Value 0 can't be removed.

A new map comes with 0 Empty, 1 Wall, 2 Water, 3 Grass, 4 Lava and 5 Spawn defined. Names and colors are only for the editor: the game only sees the number. Whether 1 is a wall is up to you, in the room or in the code.

Cell values and collision:

  • In a room, the Room tab of the scene editor picks a map as the Collision map and says which values are solid (Solid values) and which are platforms you can jump up through (One-way values). That map needs cell values: type Tiles + Cell Values or Cell Values Only. With Tile numbers on, the room collides with the tile numbers instead of the cell values. The room and the game explains it.
  • In your code, you load the cell values layer with GridMap and tell it which values are solid (solids) and which are platforms (platforms): hits resolves a sprite's collision with the map. See "From code" below.

Values also work to mark places: where an enemy appears, a door, an area that hurts… Your code finds them with find.

Visualization​

  • Show Map Grid: the map grid. On by default.
  • Show Palette Grid: the palette grid. On by default.
  • Show Cell Values: paints the cell values over the map, hatched in their color and with their number. On by default.
  • Show Tile Numbers: writes each cell's tile number in yellow. Useful when the room collides by tile number (Tile numbers in the scene editor). Off by default.
  • Include map in build: when it is off, compiling skips the map and doesn't export its .gmap files. On by default; it is stored in the .map.
  • The color box at the end, with no name: the background color for Extract Tiles.

The numbers, of values and tiles, only show with the zoom at 75 % or more and the tile at 16 pixels or more on screen.

The status bar​

At the bottom, the status bar shows the tool, the active layer and the picked tile or value, for example Tool: Brush | Layer: Tiles | Selected tile: 0, with a * at the end if there are unsaved changes. On the right, Tile: x, y is the cell under the mouse: column and row, counted from 0, the same ones get(x, y) uses in GridMap.

What it saves and what it generates​

Save saves the map in its .map, a JSON file. Home › Project › Save, on the ribbon, saves it too if it already has a file. When you save, the scene editor, if it is open, repaints the room with the new map.

.map fieldWhat it is
modeThe type: tiles (Tiles Only), tiles_cellvalues (Tiles + Cell Values) or cellvalues_only (Cell Values Only).
mapWidth, mapHeightThe map size, in tiles.
tileWidth, tileHeightThe size of a tile, in pixels.
tilesetNodeIDThe tileset: the number of its image within the project.
saveToDataInclude map in build.
tilesOne number per cell, row by row: the tile, or 65535 if the cell is empty.
cellValuesOne number per cell, row by row: the cell value.
valueDefinitionsThe defined values, with their id, name, color and description.

The tileset goes by the number of its image in the project: a .map copied from another project points to whichever image has that number in this one, or to none. Pick it again in Image.

When you compile (Build › Compile, and also the scene editor's Play), the IDE turns each .map into one or two .gmap files, in Build/flash and with the same path as the .map within the project:

FileWhat it holdsWhen
Build/flash/Maps/<map>_tiles.gmapThe tiles, one byte per cell; 255 is an empty cell.With Tiles Only or Tiles + Cell Values.
Build/flash/Maps/<map>_cells.gmapThe cell values, one byte per cell.With Tiles + Cell Values or Cell Values Only.

A .gmap starts with a 12-byte header (GMAP, the version, the map width and height, and the tile width and height) followed by one byte per cell, row by row.

The Output shows what is exported and what isn't:

  • With Include map in build off, the map isn't exported: "Skipping tilemap (saveToData is false)".
  • A map just created with New TileMap is empty until the first Save. Until then it is skipped with a warning: "The map is empty (it was never saved in the Tilemap Editor)".
  • If your game loads its rooms as data (The code it generates), a layer of a room's map that no room loads and your code doesn't name isn't exported: "Not exported, no room loads it".
  • A tile above 254 stops the compilation: "tiles have index > 254".
Save before compiling

When you compile, the IDE reads the .map from disk: neither Compile nor Play saves the tilemap editor. What you haven't saved doesn't reach the game.

Shortcuts​

ShortcutWhat it does
Ctrl+ZUndo.
Ctrl+Y or Ctrl+Shift+ZRedo.
Ctrl + wheel, over the mapZooms the map in or out.
Ctrl + wheel, over the paletteZooms the palette in or out.
Right button, over the mapErases, with any tool.
Right button, over the paletteStops picking the background color for Extract Tiles.

The keys work while the tilemap editor is active.

From code​

With rooms you don't write anything: the code the scene editor generates loads the .gmap files of its layers and of its collision map (The code it generates).

In a game written in code, load with GridMap.load what the IDE exports when compiling. If you drag the .map from the explorer onto the code editor, a menu lets you pick Load tiles map or Load cells map and writes the call for you. The tile size is inside the .gmap; you supply the tileset:

use Display, GridMap, Bitmap

var draw = Display.draw
Display.open(320, 240)
Display.fps = 30

// What Maps/Level1.map exports, of type Tiles + Cell Values
var level = GridMap.load("Maps/Level1_tiles.gmap")
level.tileset = Bitmap.load("Images/Tiles.bmp")
var cells = GridMap.load("Maps/Level1_cells.gmap")
cells.solids = [1] // value 1 (Wall) is solid

println(cells.get(3, 2)) // the value at column 3, row 2

while (true)
draw.cls()
draw.tilemap(level)
Display.update()
end
  • draw.tilemap paints the tiles and skips empty cells.
  • To make a sprite collide with the walls, call cells.hits(sprite) every frame.
  • cells.find(10) tells you where the cells with value 10 are, for example to place the enemies.

Only ask for the layers the map type has: with Tiles Only, the IDE doesn't export the _cells.gmap. Everything else is in GridMap.

Known issues​

  • A map with no file doesn't change size. In the map with no file that Home › View › TileMap gives you, Resize Map and Size do nothing. Save it first, or create the map with New TileMap.
  • Old .gmap files stay. Compiling doesn't delete what was already in Build/flash/Maps. If you turn off Include map in build, change a map's type, rename it or delete it, the .gmap from the previous compilation is still there. Delete it by hand if you don't want it.
  • Tiles above 254. The editor lets you paint them without a warning, and the error shows up when you compile (Tileset panel).

All the known issues of JARU, together, are in Known issues.