The tm commands give you maps made of tiles: build one in code or load one from Tiled, draw it in layers, change it while playing, and ask it about collisions. They work the same on desktop, Web (WebGPU) and Web (WebGL2).
Only the tiles on screen cost anything, so a huge map draws as fast as a small one, and changing a tile costs next to nothing.
The reference for every function is in Runtime Commands > Tilemap, and the examples are in examples/Runtime/37 - Tilemaps, each with a desktop and two web versions:
| Example | Shows |
| Scroller | A large scrolling map with a sprite between two layers |
| Platformer | Collisions, animated tiles, parallax and a see-through layer |
| SpeedLevel | A fast game with slopes and loops, using tile shapes |
| TiledMap | A level made in Tiled, with its objects |
| Autotile | Paint and dig terrain with the mouse |
| IsoWalk | An isometric map with a character who walks behind the walls |
| HexBoard | A hexagonal board, with a piece that moves from cell to cell |
tiles = tmTilesetCreate(b2dLoadImage("Media/tiles.png"), 16, 16, 0)
tmSetTileFlags(tiles, 5, 1) ; tile 5 is solid
map = tmCreate(200, 30, 16, 16)
ground = tmAddLayer(map, "ground", tiles)
tmFill(map, ground, 0, 25, 200, 5, 5)
; each frame
tmSetCamera(map, camX, 0)
tmDrawLayer(map, ground)
b2dDrawImage(player, px - camX, py)
If tmBoxHit(map, ground, px, py + 1, 16, 16, 1) Then onGround = True
Tile coordinates start at 0. Tile id 0 is empty, and ids from 1 count through the tileset, left to right and then down, which is how Tiled numbers them too. A bad handle or a tile outside the map is safe: gets return 0 and sets do nothing.
tmDraw draws all the visible layers in order. tmDrawLayer draws one where you call it, so to put a sprite between layers, draw them one at a time with the sprite in between.
The camera belongs to the map: tmSetCamera sets the world position at the top left of the screen. tmSetLayerParallax makes a layer move slower for a distant background, and tmSetLayerAlpha makes it see-through. b2dSetColor and b2dSetAlpha affect tiles, but b2dSetScale and rotation don't: use tmSetZoom to scale a map. Maps draw into render targets as well as to the screen.
A palette (indexed) image doesn't draw as tiles yet.
To have a sprite hidden by what's in front of it and drawn over what's behind it, all in one layer, draw the layer a row at a time, from the back. Put each sprite in after the row its feet are in:
For row:Int = 0 To tmRowCount(map) - 1
tmDrawLayerRow(map, ground, row)
If tmRowAt(map, footX, footY) = row Then b2dDrawImage(player, footX - 12 - camX, footY - 44 - camY)
Next
It works on every shape of map, so a top-down game can walk behind a tree this way too. With many sprites, keep a list of them for each row. Each row is usually its own draw call, so use tmDrawLayer or tmDraw for layers with no sprites in them.
A sprite sorts by one point, its feet. An object much wider than a cell can still overlap wrongly, so split it into pieces, one a cell.
Load one from Tiled, or make one with tmCreate and tmSetOrientation (1 isometric, 2 staggered, 3 hexagonal). Give tmCreate the size of the grid, such as 64 by 32. The tile pictures can be taller, and sit on the bottom of their cell, so a wall can rise above it. Set the tileset's size to the picture's.
tiles = tmTilesetCreate(b2dLoadImage("Media/iso_tiles.png"), 64, 64, 0)
map = tmCreate(24, 24, 64, 32)
tmSetOrientation(map, 1)
ground = tmAddLayer(map, "ground", tiles)
Tiles are set and read by their cell as usual. World positions are where things are on screen before the camera: tmSetCamera, tmObjectX and tmObjectY use them. tmTileXAt and tmTileYAt give the cell at a world position, which is what to use with the mouse. tmTileAt takes one too, and tmTileCentreX and tmTileCentreY give one back.
Grid positions are for moving things on an isometric map. In them the map is square, and each cell is the grid's height both ways, so 32 by 32 on a 64 by 32 map. These are the same numbers Tiled shows for an object. Move a character in grid positions, and turn them into world positions to draw:
If tmBoxHit(map, ground, gridX - 8, gridY - 8, 16, 16, 1) = 0 Then Move() footX = tmGridToWorldX(map, gridX, gridY) footY = tmGridToWorldY(map, gridX, gridY)
tmBoxHit, tmRayCast, tmPixelSolid and tmProbe take grid positions on an isometric map, and tiles count as fully solid: masks are for square maps. tmGroundProbe is for side-on games and isn't useful here.
On staggered and hexagonal maps those collision commands return 0, as the cells don't line up in straight lines. Work from cell to cell instead: tmNeighbourX and tmNeighbourY give the cell next to one in a direction, and tmGetTile and tmGetTileFlags tell you what's there.
map = tmCreate(19, 14, 64, 64) tmSetOrientation(map, 3) tmSetHexSide(map, 32) ; the length of a hexagon's flat sides tmSetStagger(map, 0, 0) ; move rows (1 for columns), the odd ones (1 for even)
Directions on these maps go clockwise from 0 to 5: from east if they're staggered by row, from north if by column. tmDrawLayerRow still runs from the back to the front. When a map staggers by column, each y has two rows, so use tmRowCount and tmRowAt rather than the y. Tiled's 60 and 120 degree tile turns come across on hexagonal maps; tmSetTileFlip sets them as 8 and 16.
The commands only answer questions. Your game decides what happens. Flags are bits that mean whatever you want, set per tile with tmSetTileFlags, and a flags value of 0 in a query means any tile that isn't empty.
| Command | Asks |
| tmTileAt | Which tile is at this world position? |
| tmBoxHit | Does this box touch a tile with these flags? |
| tmRayCast | What's the first tile with these flags along this line? |
| tmPixelSolid | Is this pixel solid? |
| tmProbe | How far along this direction is the first solid pixel? |
| tmGroundProbe | Where does a round body stand on this ground, and at what angle? |
After a hit, tmHitX, tmHitY, tmHitTile, tmHitWorldX and tmHitWorldY give the details.
Tile shapes: a tile is fully solid unless it has a mask. tmMasksFromImage takes the shapes from the art, and tmSetTileMask sets one by hand. All the collision commands respect masks and flips. For a level whose shapes differ from its art, keep the shapes on a hidden layer with tmTilesetCreateBlank, as SpeedLevel does.
A terrain is a block of tiles in your tileset. Tell the tileset where it is, then paint with tmSetTileAuto, which picks the right tile for the cell and its neighbours. Terrain 0 digs.
tmSetTerrain(tiles, 1, 1, 47) ; terrain 1: 47 tiles from id 1 tmSetTileAuto(map, ground, x, y, 1) ; paint tmSetTileAuto(map, ground, x, y, 0) ; dig
A cell belongs to a terrain if its tile id is in that block, so tiles from tmSetTile and loaded maps join in. Different terrains don't join, and other tiles are left alone. The edge of the map counts as the same terrain, so ground can run off the map with no border.
The block's order is worked out from which neighbours are the same terrain:
Layout 16 looks at the four sides, and has no inside corners. The tile is the first tile + the total of: north 1, east 2, south 4, west 8. Draw its edges right up to the side of the tile, with no gap. It can't see diagonals, so a tile at a bend is filled to its corner: an edge can't wrap around an inside corner. If your art needs that, use layout 47.
Layout 47 has a tile for every shape. Add up: north 1, north-east 2, east 4, south-east 8, south 16, south-west 32, west 64, north-west 128, where a corner only counts if both sides beside it are the same terrain too. That leaves 47 different totals, and the tiles are in order of them:
0 1 4 5 7 16 17 20 21 23 28 29 31 64 65 68 69 71 80 81 84 85 87 92 93 95 112 113 116 117 119 124 125 127 193 197 199 209 213 215 221 223 241 245 247 253 255
This is the order commonly called "blob" tiles. Tilemap/make_autotile_example.py in the source draws the Autotile example's sheet, if you'd like to see one built.
Paint your map in Tiled, then use File > Export As to save it as JSON (.tmj). For tilesets, turn on Embed tilesets under Edit > Preferences > General, or also export them as JSON (.tsj). Keep the images where the file says they are.
map = tmLoad("Media/level.tmj")
; each frame
If tmLoaded(map) = 1 Then tmDraw(map) ; 1 ready, 0 still waiting, -1 failed
On the desktop the map is ready as soon as tmLoad returns. On the web it loads in the background, so check tmLoaded first. Use tmGetLayer to find layers by name and tmLayerTileset to reach their tilesets.
Custom properties: give a tile solid (true), flags (a number) or value (a number) in Tiled's tileset editor, and they become its flags and value. Tile animations come across too, with any frames and timings.
Objects: use tmObjectCount to go through an object layer, with tmObjectName, tmObjectType, tmObjectX and friends. tmObjectProp reads custom properties as text. Tile objects draw in their layer's place, so object layers and image layers count as layers. Other shapes aren't drawn, as they're for your game to read.
| Tiled feature | In BambooBasic |
| Orthogonal, isometric, staggered and hexagonal maps, with either Stagger Axis; CSV, Base64, zlib and gzip layers; group layers | Yes |
| Several tilesets in one layer | Yes (see below) |
| Image layers: position, opacity, parallax, repeat and transparent colour | Yes |
| Infinite orthogonal maps | Yes (see below) |
| The map's background colour | Yes, with tmUseBackground |
| Embedded and .tsj tilesets, margins, spacing, tile offset, transparent colour, tiles bigger than the grid, image collections | Yes |
| Flipped and rotated tiles; layer opacity, visibility and parallax | Yes |
| Infinite maps that aren't orthogonal, zstd, .tmx and .tsx files | No: the map won't load, or the layer is left out, with a message saying why |
| Object templates (export with Detach templates) | No: left out, with a warning |
| Tile layer offsets, layer tint colours, and a group layer's own opacity, offset and parallax | Not read, with no warning |
Several tilesets in one layer: a layer that uses only one tileset works as normal, with ids counting from 1 in that tileset. A layer that uses more has them all put together into one tileset, which tmLayerTileset gives you, and its ids are the numbers Tiled uses across the map. So the first tile of a tileset that Tiled numbers from 21 is id 21. Flags, values and animations come across. tmMasksFromImage does nothing on one of these, so give shaped tiles their masks with tmSetTileMask.
Infinite maps: the map becomes as big as what you've painted, with the top left painted tile at cell 0,0. Objects and image layers move with it, so they stay in the same place relative to the tiles, but their positions won't match the numbers shown in Tiled.
Background colour: tmUseBackground sets b2dCls's colour from the map. On the web, call it once tmLoaded says the map has arrived.
BambooBasic © 2026 Michael Denathorn