Phaser home
Phaser AE
Open source
Phaser 4
Download
Learn
Editor
Tools
Docs
Examples
News
Log in
Examples
/
Tilemap
Phaser 4.1.0
Phaser 4 examples
Tilemap
69
examples
3
folders
Folders
3
Collision
12 examples
Isometric
3 examples
Tests
6 examples
Examples
48
Base Tile Size
Learn how to use a base grid size that differs from the tileset dimensions, allowing larger tiles to overlap vertically on a smaller map grid.
Convert Tiles to Sprites
Transform specific tile indices from a tilemap into dynamic Sprite objects using createFromTiles. This example demonstrates using a spritesheet to automatically set the correct texture frames for the converted sprites.
Copy Tilemap Area
Learn how to copy a rectangular region of tiles from one location to another within a tilemap layer.
Create Sprites From Tilemap Objects
Demonstrates how to use createFromObjects to automatically convert Tiled map object data into Phaser Sprites, inheriting positions and custom properties.
Create Tilemap from Array
This example demonstrates how to create a tilemap directly from a 2D JavaScript array of tile indices instead of loading an external data file.
Creating Blank Layers
Generate an empty tilemap programmatically and populate it with new blank layers. This example demonstrates how to use the randomize method to fill layers with tiles and how to apply parallax effects using scale and scroll factors.
CSV Tilemap
Demonstrates how to load and display a tilemap from a CSV file, including the requirement to manually specify tile dimensions when creating the map.
Dungeon Generator
Learn how to convert a procedurally generated dungeon layout into a dynamic Tilemap. This example demonstrates using weighted randomization for varied tile textures, tile-based collision, and a room discovery system that reveals areas as the player explores.
Fill Tiles
Demonstrates how to use the fill method to replace a specific rectangular area of tiles with a new tile index based on the pointer position.
Get Tiles Within Geometric Shapes
Demonstrates how to use getTilesWithinShape to find tiles that intersect with a Rectangle, Circle, Line, or Triangle, with optional filtering for only colliding tiles.
Grid Movement
Implement grid-based movement and tile-based collision detection by checking tile indices at specific world coordinates before updating a sprite position.
High Resolution Tilemap Support
Shows how to load a 16x16 tileset into a map originally designed for 8x8 tiles by setting a custom base tile size.
Infinite Scrolling Tilemap
Demonstrates how to create an endless scrolling effect by shifting tile indices across a map and procedurally generating new tile columns on the edge.
Load Tiled JSON Map
Demonstrates how to load a Tiled JSON map file, associate it with a tileset image, and render a scrollable layer using camera controls.
Map vs. Layer with One Layer
Learn how tile manipulation methods like fill and randomize can be called on either the Tilemap or the TilemapLayer when working with a single-layer map.
Mario Map Scroller
Learn how to render multiple Tiled JSON maps in a single scene and use a FixedKeyControl to scroll the camera horizontally across them.
Multi-Camera Tilemap View
Demonstrates rendering a single tilemap layer across multiple cameras simultaneously, with one camera featuring independent zoom, rotation, and smoothed keyboard controls.
Multiple Tilesets
Demonstrates how to render a single tilemap layer using tiles from multiple different tileset images by passing an array of tilesets to createLayer.
Paint Tiles
Interactively edit a tilemap by picking and placing tiles at runtime. Demonstrates coordinate conversion from screen to world/tile space and using putTileAt to modify a layer dynamically.
Pixel Art Scaled Tilemap
Demonstrates scaling a tilemap layer and using a FixedKeyControl to navigate the camera across the map.
Placing Tiles Dynamically
Learn how to use putTileAt and putTilesAt to manually place single tiles, rows of tiles, or 2D arrays of tiles onto a tilemap layer based on pointer coordinates.
Randomize Tiles
Demonstrates how to use the Tilemap randomize method to fill a specific rectangular area with random tiles based on existing tile indexes or a specific list of tile IDs.
Replace Tiles by Index
Demonstrates how to use the replaceByIndex method to search for all instances of a specific tile index and swap them with a new tile across a map layer.
Set Colliding Tiles
Demonstrates multiple ways to enable tilemap collisions using setCollision, setCollisionBetween, and arrays, while visualizing the results with debug rendering.
Set Tilemap Collision by Property
Enable collision for tiles based on custom data properties defined in Tiled, rather than using specific tile IDs or ranges.
Set Tilemap Layer Width
Demonstrates how to programmatically adjust the width of a tilemap layer to clip its visible rendering area.
Shuffle Tiles
Demonstrates how to use the shuffle method to randomly rearrange a specific rectangular area of tiles within a tilemap layer.
Swap Tile Indices
Use swapByIndex to find all instances of a specific tile across the map and swap them with a different tile index.
Switching Active Tilemap Layers
Demonstrates how to manage multiple tilemap layers and use map.setLayer to change which layer is targeted by map-level tile operations.
Switching Tileset Textures
Demonstrates how to change the visual appearance of a tilemap at runtime by dynamically swapping the tileset's underlying texture using the setImage method.
Tile Properties
Demonstrates how to access and display custom properties defined for specific tiles within a Tiled JSON map.
Tiled Multi Tileset
Demonstrates how to render a single tilemap layer that uses multiple different tileset source images by passing an array of tilesets to the layer creation method.
Tilemap Chebyshev Distance
Calculate the Chebyshev distance between the player's current tile and all other tiles in the map to create a dynamic visibility effect.
Tilemap Collision Debugging
Demonstrates how to use the renderDebug method to visualize tilemap collision data, including highlighting specific colliding tiles and their active edges (faces).
Tilemap Collision From Tiled Shapes
Enable collisions on a Tilemap layer using the collision shapes defined in the Tiled editor via setCollisionFromCollisionGroup, with Matter.js physics integration.
Tilemap Layer Collision
Demonstrates how to enable collision between a physics-enabled sprite and specific tile indices within a Tilemap layer.
Tilemap Layer Filter
Demonstrates how to apply a custom shader filter to a specific Tilemap layer while performing tile-based collision detection.
Tilemap Layer Size
Demonstrates how to manually adjust the width of a tilemap layer to clip its rendering area and position multiple layers from different tilemaps within the same scene.
Tilemap Layer Width and Camera Bounds
Demonstrates how to modify the width of a Tilemap Layer and adjust camera bounds to match the new dimensions.
Tilemap Lighting and Normal Maps
Demonstrates applying Phaser's 2D lighting system to a tilemap layer, featuring normal maps for texture depth, ambient light settings, and dynamic point lights that follow the player.
Tilemap Minimap Zoom
Demonstrates how to create a secondary camera with a low zoom level to act as a scrolling minimap for a tilemap.
Tilemap Mouse Wheel Zoom
Demonstrates how to zoom a camera toward the mouse pointer using the wheel event and implement drag-to-pan functionality over a tilemap.
Tilemap Render Order
Demonstrates how to change the rendering sequence of tiles within a layer using setRenderOrder to handle different tile overlap perspectives.
Tilemap Snake Distance
Adjust tile transparency dynamically based on the Manhattan distance (Snake distance) between the player and each tile in the map.
Tilemap Weighted Randomization
Demonstrates using weightedRandomize to fill a specific area of a tilemap layer with tiles based on probability weights, useful for procedural floor patterns and item distribution.
Tileset Collision Shapes
Access and visualize collision shapes (rectangles, ellipses, and polygons) and custom properties defined within a Tiled tileset.
Tileset with Margin and Spacing
Demonstrates how to use tilesets that include margins and padding between tiles, covering both Tiled JSON maps and manual configuration via addTilesetImage.
Tint Tilemap Layer
Demonstrates how to apply color tints to specific rectangular regions of tiles within a Tilemap Layer.