phaserjs/phaser/tilemaps
Claude Code and agent skill by phaserjs/phaser
- community
Checking that the SKILL.md file is still in the repository.
Tile maps in Phaser 4: load.tilemapTiledJSON and load.tilemapCSV, make.tilemap, addTilesetImage, createLayer and createBlankLayer, TilemapGPULayer, getTileAt, putTileAt, removeTileAt, getTilesWithinShape, tile collision with setCollisionByProperty and setCollision, Arcade colliders, object layers with createFromObjects, isometric, hexagonal and staggered maps, and layer culling. Use when building a level, platformer or dungeon map, a procedural or editable map, or placing enemies and pickups from Tiled. Corrects: Tiled tile IDs are not tile indexes, an overlap with a layer includes empty tiles, putTileAt keeps the old tile's properties, and the GPU layer is WebGL, orthogonal and single-tileset. Triggers on: tilemap, Tiled, tileset, tile layer, tile collision, object layer.
Install
npx vskill@latest install phaserjs/phaser/tilemapsSKILL.md
The same SKILL.md was published earlier as phaserjs/phaser/tilemaps.
Tilemaps
A Tilemap holds the parsed map data and is not drawn. Its layers, TilemapLayer (CPU, every renderer and orientation) or TilemapGPULayer (WebGL, orthogonal), are the Game Objects that draw tiles. Most tile methods live on TilemapLayerBase, shared by both.
Source: src/tilemaps/Tilemap.js, src/tilemaps/TilemapLayerBase.js, src/tilemaps/TilemapLayer.js, src/tilemaps/TilemapGPULayer.js, src/tilemaps/Tile.js, src/tilemaps/Tileset.js, src/tilemaps/components/, src/tilemaps/parsers/tiled/. Related: physics-arcade, physics-matter, loading-assets, cameras.
Quick start
A platformer level from Tiled, with Arcade Physics enabled in the game config.
The other snippets continue this one: map, tileset, ground and this.player come from here.
this.make.tilemap(config)andthis.add.tilemap(key)both return a Tilemap. Neither is on the display list.- In Tiled, embed the tilesets in the map. External
.tsxtilesets aren't loaded. Compressed layer data (zlib, gzip, zstd) is skipped with a warning, so save layers as CSV or uncompressed Base64. Infinite maps work.
Tilesets and layers
map.addTilesetImage(tilesetName, key, tileWidth, tileHeight, tileMargin, tileSpacing, gid, tileOffset)
tilesetNameis the tileset's name inside Tiled, not a file name. If it doesn't match, the method returnsnulland logs the map's tilesets.keydefaults totilesetName.- A Tiled map supplies the tile size, margin and spacing. Pass them only to override.
- The Tileset uses the whole texture image. Atlas frames are ignored, and a multi-atlas texture isn't supported (only its first image is used). Use the DynamicTexture workaround below.
- Image collection tilesets ("Collection of Images" in Tiled) are parsed. Each image becomes its own Tileset, named by the image path as written in the JSON. Since 4.3 they keep their tile properties, type and collision group.
map.createLayer(layerID, tileset, x, y, gpu)
layerIDis the Tiled layer name or its index. Layers inside a Tiled group are named'Group/Layer'. An unknown name returnsnulland logs the valid names.- Each layer can be created once. A second call returns
null. xandydefault to the layer's offset in Tiled, not (0, 0).- Layers draw in creation order. Use
setDepthto put sprites between them.
A tileset from atlas frames
A Tileset needs one image laid out as a grid. To build one from atlas or multi-atlas frames, stamp them into a DynamicTexture in the order the Tiled tileset expects.
Maps without Tiled
- CSV:
this.load.tilemapCSV('cave', 'assets/cave.csv'), thenthis.make.tilemap({ key: 'cave', tileWidth: 32, tileHeight: 32 })andcreateLayer(0, ...). insertNull: truein themake.tilemapconfig stores empty cells asnullinstead of index -1 Tiles, which saves memory on large sparse maps.putTileAtstill works on those cells.getTileAt(x, y, true)returnsnullfor them, and an overlap skips them.
Tiles
tile.indexis the global tile index. In a Tiled map it is the tile's ID in Tiled plus its tileset'sfirstgid(usually 1). The ID shown in Tiled's tileset editor is not the index. -1 is an empty cell.tile.xandtile.yare in tiles.tile.pixelXandtile.pixelYare relative to the layer.tile.getCenterX()andtile.getCenterY()are in world space.tile.propertiesis a plain object, copied from the tileset when the map is parsed.- Tiled's flip and rotate flags arrive as
tile.rotation(radians) andtile.flipX. A vertical flip in Tiled isrotation = Math.PIwithflipX = true, sotile.flipYstaysfalse. tile.tint,tile.tint2(4.2) andtile.tintModework on a CPU layer.layer.setTint(color, tileX, tileY, width, height),setTint2andsetTintModeset them on a region. The tint modes are in game-object-components. A GPU layer ignores tile tint, alpha and visibility.
Get, put and remove
getTileAt(tileX, tileY, nonNull):nonNullis the third positional argument.truereturns an index -1 Tile for an empty cell instead ofnull. Outside the layer, and fornullcells, the result is stillnull.putTileAtchanges the index of the Tile in that cell. It doesn't refreshproperties, and the tile collides only if its index was recorded bysetCollision,setCollisionBetweenorsetCollisionByExclusion. Only put indexes that one of the map's tilesets contains: an unknown index throws.removeTileAt(tileX, tileY, replaceWithNull, recalculateFaces):replaceWithNulldefaults totrue, so the cell becomesnull. Passfalseto leave an index -1 Tile.- TypeScript: since 4.3,
getTileAt,getTileAtWorldXY,putTileAt,putTileAtWorldXY,removeTileAtandremoveTileAtWorldXYreturnTile | null. WithstrictNullChecks, check the result before using it. - Every tile method also exists on the Tilemap with an extra last
layerargument, acting on the current layer (map.setLayer) when it's left out. Call them on the layer instead. - Regions and searches:
getTilesWithin,getTilesWithinWorldXY,filterTiles,findTile,forEachTile. TheirfilteringOptionsare{ isNotEmpty, isColliding, hasInterestingFace }. Editing:fill,putTilesAt,randomize,weightedRandomize,replaceByIndex,swapByIndex,copy,shuffle. Coordinates:worldToTileXY,tileToWorldXY. Seesrc/tilemaps/TilemapLayerBase.js.
Tiles inside a shape
getTilesWithinShape(shape, filteringOptions, camera) takes a Circle, Line, Rectangle or Triangle in world coordinates. Since 4.3 it works on isometric layers, testing each tile's diamond. On hexagonal and staggered layers it logs a warning and returns [].
Collision with Arcade Physics
- A collider tests only tiles marked as colliding, so mark them first. An overlap tests every tile under the body, colliding or not, including empty ones with an index of -1. Check
tile.indexor a property in the callback. - The callbacks always get
(sprite, tile), whichever order you pass them in. - Tile callbacks:
layer.setTileIndexCallback(indexes, callback, context),layer.setTileLocationCallback(tileX, tileY, width, height, callback, context)andtile.setCollisionCallback(callback, context). They run only while a collider or overlap exists between the body and the layer: for colliding tiles with a collider, and for every tile with an overlap. A tile callback which returnstruecancels the collision with that tile. - Only the index methods record indexes for tiles placed later.
setCollisionByExclusionrecords only the indexes in the layer when it's called.setCollisionByPropertyandsetCollisionFromCollisionGrouprecord nothing, so settile.setCollision(true)on tiles you place. - One-way tile:
tile.setCollision(false, false, true, false)(left, right, up, down) collides on the top face only. - A layer has
collisionCategoryandcollisionMasklike a body, both 1 by default. See physics-arcade. - Arcade treats each tile as a box, so tile collision is only correct on orthogonal maps.
- Matter: call
this.matter.world.convertTilemapLayer(ground)after setting collision. See physics-matter.
renderDebug draws once, for orthogonal maps. Use a Graphics just for it, and clear() it before calling again.
Object layers
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/tilemaps/SKILL.md
Popularity
- Repository stars
- 39,633
- Repository forks
- 7,130
- 7-day trend score
- 53
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Grok Build (Cursor)
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/phaserjs/phaser/tilemaps)