Skip to main content

Introduction to TileMaps

TileMaps are a powerful system for creating grid-based levels efficiently. They allow you to paint levels using tiles from a TileSet.
As of Godot 4.0+, the recommended approach is to use TileMapLayer nodes. The legacy TileMap node is deprecated but still functional.

TileMap Basics

Creating a TileMap

  1. Add a TileMap node to your scene
  2. Create or assign a TileSet resource in the Inspector
  3. Open the TileMap editor at the bottom of the screen
  4. Select tiles and paint them in the viewport

Setting Up in Code

TileMap Layers

TileMaps support multiple layers for organizing tiles:

Coordinate System

TileSet

A TileSet is a resource containing all tile definitions.

Creating a TileSet from Texture

  1. Create a new TileSet resource
  2. Add an Atlas source
  3. Select your texture atlas
  4. Configure tile size
  5. Define tiles and their properties

TileSet in Code

Working with Tiles

Setting Tiles

Reading Tiles

Getting Used Cells

Autotiling and Terrains

Terrains automatically choose the correct tile based on neighboring tiles.

Setting Up Terrain Sets

  1. In TileSet editor, create a Terrain Set
  2. Define terrains (grass, dirt, water, etc.)
  3. Paint terrain bits on each tile
  4. Godot will automatically pick correct tiles when painting

Using Terrains in Code

Alternative Tiles

Create variations of the same tile:

Physics in TileMaps

Setting Up Collision

  1. Select a tile in the TileSet editor
  2. Switch to the Physics Layers tab
  3. Draw collision polygons for the tile
  4. Configure physics layers and masks

Physics Layer Configuration

Detecting Tile Collisions

Custom Data Layers

Store custom data per tile:

Adding Custom Data

  1. In TileSet editor, add a Custom Data Layer
  2. Name it (e.g., “damage”, “speed_modifier”)
  3. Set the type (int, float, string, etc.)
  4. Set values for each tile

Reading Custom Data

TileMap Patterns

Save and reuse tile patterns:
TileMaps can generate navigation regions automatically:

Setting Up Navigation

  1. In TileSet editor, add a Navigation Layer
  2. Draw navigation polygons for walkable tiles
  3. Enable layer navigation in TileMap

Procedural Generation

Performance Optimization

Rendering Quadrant Size

Clearing Cells Efficiently

Advanced Example: Destructible Terrain

Clicking on Tiles

Best Practices

Terrain sets automatically handle tile connections, saving time and ensuring consistency.
Use separate layers for ground, decorations, and foreground objects.
Store tile properties (damage, speed modifiers) in custom data layers instead of hard-coding.
If checking the same tile repeatedly, cache the result to avoid repeated lookups.

Next Steps

Physics

Learn more about collision and physics

Canvas Layers

Organize rendering with canvas layers