-
Notifications
You must be signed in to change notification settings - Fork 4
Tilemaps
samme edited this page Aug 5, 2023
·
32 revisions
- Modular Game Worlds in Phaser 3 — Static Maps
- Modular Game Worlds in Phaser 3 — Dynamic Platformer
- Modular Game Worlds in Phaser 3 — Procedural Dungeon
- Tilemap file: a Tiled JSON or CSV file
- Tilemap:
- Layer data: a 2-dimensional array (grid) of tiles
- Tile: a tile placed on a map layer
- Tileset: a mapping of tile IDs onto a tileset image
- Object layer: a nonrenderable layer with object data, created in Tiled
- Layer data: a 2-dimensional array (grid) of tiles
- Tilemap layer: a game object on the scene display list, rendering one map layer data
The basic procedure is:
- Load a tileset image
- Load a tilemap file, if using one
- Create a tilemap object
- Assign tileset images to the tilemap
- Create a tilemap layer, specifying one or more tilesets for it
Every tilemap layer needs at least one tileset image to render. You assign this to the map with addTilesetImage()
.
load.image()
is fine for this, but you can also use load.spritesheet()
(with the appropriate frame dimensions) if you want to use the tileset image as a multiframe texture for other game objects like sprites.
- Tiled JSON map example
- Tiled multiple tilesets example
- Static Maps: Building a Map in Tiled etc.
In Tiled,
- Create a map. Choose uncompressed data format.
-
Export as JSON
- Embed tilesets
- Detach templates
- Resolve object types and properties
const map = this.add.tilemap(/*…*/);
const [firstObjectLayer] = map.objects;
console.info('Object properties in %s:', firstObjectLayer.name);
console.table(firstObjectLayer.objects);
console.info('Object custom properties in %s:', firstObjectLayer.name);
console.table(firstObjectLayer.objects.map(o => o.properties));