Node for 2D tile-based maps.
    public class TileMap : Node2D

Node for 2D tile-based maps. Tilemaps use a TileSet which contain a list of tiles (textures plus optional collision, navigation, and/or occluder shapes) which are used to create grid-based maps.

Inheritance Chain

Static Fields

    public const Int32 InvalidCell = -1

Constructors

    public TileMap()

Signals

    "settings_changed" ()

Emitted when a tilemap setting has changed.

Properties

    public bool CellClipUv { get; set; }

    public Transform2D CellCustomTransform { get; set; }

The custom Transform2D to be applied to the TileMap’s cells.

    public HalfOffset CellHalfOffset { get; set; }

Amount to offset alternating tiles. See HalfOffset for possible values.

    public int CellQuadrantSize { get; set; }

The TileMap’s quadrant size. Optimizes drawing by batching, using chunks of this size.

    public Vector2 CellSize { get; set; }

The TileMap’s cell size.

    public TileOrigin CellTileOrigin { get; set; }

Position for tile origin. See TileOrigin for possible values.

    public bool CellYSort { get; set; }

If true, the TileMap’s children will be drawn in order of their Y coordinate.

    public bool CenteredTextures { get; set; }

If true, the textures will be centered in the middle of each tile. This is useful for certain isometric or top-down modes when textures are made larger or smaller than the tiles (e.g. to avoid flickering on tile edges). The offset is still applied, but from the center of the tile. If used, CompatibilityMode is ignored.

If false, the texture position start in the top-left corner unless CompatibilityMode is enabled.

    public float CollisionBounce { get; set; }

Bounce value for static body collisions (see collision_use_kinematic).

    public float CollisionFriction { get; set; }

Friction value for static body collisions (see collision_use_kinematic).

    public uint CollisionLayer { get; set; }

The collision layer(s) for all colliders in the TileMap.

    public uint CollisionMask { get; set; }

The collision mask(s) for all colliders in the TileMap.

    public bool CollisionUseKinematic { get; set; }

If true, TileMap collisions will be handled as a kinematic body. If false, collisions will be handled as static body.

    public bool CollisionUseParent { get; set; }

    public bool CompatibilityMode { get; set; }

If true, the compatibility with the tilemaps made in Godot 3.1 or earlier is maintained (textures move when the tile origin changes and rotate if the texture size is not homogeneous). This mode presents problems when doing flip_h, flip_v and transpose tile operations on non-homogeneous isometric tiles (e.g. 2:1), in which the texture could not coincide with the collision, thus it is not recommended for isometric or non-square tiles.

If false, the textures do not move when doing flip_h, flip_v operations if no offset is used, nor when changing the tile origin.

The compatibility mode doesn’t work with the CenteredTextures option, because displacing textures with the CellTileOrigin option or in irregular tiles is not relevant when centering those textures.

    public ModeEnum Mode { get; set; }

The TileMap orientation mode. See Mode for possible values.

    public int OccluderLightMask { get; set; }

The light mask assigned to all light occluders in the TileMap. The TileSet’s light occluders will cast shadows only from Light2D(s) that have the same light mask(s).

    public TileSet TileSet { get; set; }

The assigned TileSet.

Methods

    public void Clear()

Clears all cells.

    public void FixInvalidTiles()

Clears cells that do not exist in the tileset.

    public int GetCell(int x, int y)

Returns the tile index of the given cell. If no tile exists in the cell, returns [constant INVALID_CELL].

    public Vector2 GetCellAutotileCoord(int x, int y)

    [Obsolete("GetCellSize is deprecated. Use the CellSize property instead.")]
    public Vector2 GetCellSize()

Getter for CellSize

    public int GetCellv(Vector2 position)

Returns the tile index of the cell given by a Vector2. If no tile exists in the cell, returns [constant INVALID_CELL].

    [Obsolete("GetClipUv is deprecated. Use the CellClipUv property instead.")]
    public bool GetClipUv()

Getter for CellClipUv

    [Obsolete("GetCollisionBounce is deprecated. Use the CollisionBounce property instead.")]
    public float GetCollisionBounce()

Getter for CollisionBounce

    [Obsolete("GetCollisionFriction is deprecated. Use the CollisionFriction property instead.")]
    public float GetCollisionFriction()

Getter for CollisionFriction

    [Obsolete("GetCollisionLayer is deprecated. Use the CollisionLayer property instead.")]
    public uint GetCollisionLayer()

    public bool GetCollisionLayerBit(int bit)

Returns true if the given collision layer bit is set.

    [Obsolete("GetCollisionMask is deprecated. Use the CollisionMask property instead.")]
    public uint GetCollisionMask()

    public bool GetCollisionMaskBit(int bit)

Returns true if the given collision mask bit is set.

    [Obsolete("GetCollisionUseKinematic is deprecated. Use the CollisionUseKinematic property instead.")]
    public bool GetCollisionUseKinematic()

Getter for CollisionUseKinematic

    [Obsolete("GetCollisionUseParent is deprecated. Use the CollisionUseParent property instead.")]
    public bool GetCollisionUseParent()

Getter for CollisionUseParent

    [Obsolete("GetCustomTransform is deprecated. Use the CellCustomTransform property instead.")]
    public Transform2D GetCustomTransform()

Getter for CellCustomTransform

    [Obsolete("GetHalfOffset is deprecated. Use the CellHalfOffset property instead.")]
    public HalfOffset GetHalfOffset()

Getter for CellHalfOffset

    [Obsolete("GetMode is deprecated. Use the Mode property instead.")]
    public ModeEnum GetMode()

Getter for Mode

    [Obsolete("GetOccluderLightMask is deprecated. Use the OccluderLightMask property instead.")]
    public int GetOccluderLightMask()

Getter for OccluderLightMask

    [Obsolete("GetQuadrantSize is deprecated. Use the CellQuadrantSize property instead.")]
    public int GetQuadrantSize()

Getter for CellQuadrantSize

    [Obsolete("GetTileOrigin is deprecated. Use the CellTileOrigin property instead.")]
    public TileOrigin GetTileOrigin()

Getter for CellTileOrigin

    [Obsolete("GetTileset is deprecated. Use the TileSet property instead.")]
    public TileSet GetTileset()

Getter for TileSet

    public Godot.Collections.Array GetUsedCells()

Returns a Vector2 array with the positions of all cells containing a tile from the tileset (i.e. a tile index different from -1).

    public Godot.Collections.Array GetUsedCellsById(int id)

Returns an array of all cells with the given tile id.

    public Rect2 GetUsedRect()

Returns a rectangle enclosing the used (non-empty) tiles of the map.

    public bool IsCellTransposed(int x, int y)

Returns true if the given cell is transposed, i.e. the X and Y axes are swapped.

    public bool IsCellXFlipped(int x, int y)

Returns true if the given cell is flipped in the X axis.

    public bool IsCellYFlipped(int x, int y)

Returns true if the given cell is flipped in the Y axis.

    [Obsolete("IsCenteredTexturesEnabled is deprecated. Use the CenteredTextures property instead.")]
    public bool IsCenteredTexturesEnabled()

Getter for CenteredTextures

    [Obsolete("IsCompatibilityModeEnabled is deprecated. Use the CompatibilityMode property instead.")]
    public bool IsCompatibilityModeEnabled()

Getter for CompatibilityMode

    [Obsolete("IsYSortModeEnabled is deprecated. Use the CellYSort property instead.")]
    public bool IsYSortModeEnabled()

Getter for CellYSort

    public Vector2 MapToWorld(Vector2 mapPosition, bool ignoreHalfOfs = false)

Returns the global position corresponding to the given tilemap (grid-based) coordinates.

Optionally, the tilemap’s half offset can be ignored.

    public void SetCell(int x, int y, int tile, bool flipX = false, bool flipY = false, bool transpose = false, Vector2? autotileCoord = default(Vector2?))

Sets the tile index for the cell given by a Vector2.

An index of -1 clears the cell.

Optionally, the tile can also be flipped, transposed, or given autotile coordinates.

Note: Data such as navigation polygons and collision shapes are not immediately updated for performance reasons.

If you need these to be immediately updated, you can call UpdateDirtyQuadrants().

Overriding this method also overrides it internally, allowing custom logic to be implemented when tiles are placed/removed:

[codeblock]

func set_cell(x, y, tile, flip_x, flip_y, transpose, autotile_coord)

Write your custom logic here.

To call the default method:

.set_cell(x, y, tile, flip_x, flip_y, transpose, autotile_coord)

[/codeblock]

    [Obsolete("SetCellSize is deprecated. Use the CellSize property instead.")]
    public void SetCellSize(Vector2 size)

Setter for CellSize

    public void SetCellv(Vector2 position, int tile, bool flipX = false, bool flipY = false, bool transpose = false)

Sets the tile index for the given cell.

An index of -1 clears the cell.

Optionally, the tile can also be flipped or transposed.

Note: Data such as navigation polygons and collision shapes are not immediately updated for performance reasons.

If you need these to be immediately updated, you can call UpdateDirtyQuadrants().

    [Obsolete("SetCenteredTextures is deprecated. Use the CenteredTextures property instead.")]
    public void SetCenteredTextures(bool enable)

Setter for CenteredTextures

    [Obsolete("SetClipUv is deprecated. Use the CellClipUv property instead.")]
    public void SetClipUv(bool enable)

Setter for CellClipUv

    [Obsolete("SetCollisionBounce is deprecated. Use the CollisionBounce property instead.")]
    public void SetCollisionBounce(float value)

Setter for CollisionBounce

    [Obsolete("SetCollisionFriction is deprecated. Use the CollisionFriction property instead.")]
    public void SetCollisionFriction(float value)

Setter for CollisionFriction

    [Obsolete("SetCollisionLayer is deprecated. Use the CollisionLayer property instead.")]
    public void SetCollisionLayer(uint layer)

    public void SetCollisionLayerBit(int bit, bool value)

Sets the given collision layer bit.

    [Obsolete("SetCollisionMask is deprecated. Use the CollisionMask property instead.")]
    public void SetCollisionMask(uint mask)

    public void SetCollisionMaskBit(int bit, bool value)

Sets the given collision mask bit.

    [Obsolete("SetCollisionUseKinematic is deprecated. Use the CollisionUseKinematic property instead.")]
    public void SetCollisionUseKinematic(bool useKinematic)

Setter for CollisionUseKinematic

    [Obsolete("SetCollisionUseParent is deprecated. Use the CollisionUseParent property instead.")]
    public void SetCollisionUseParent(bool useParent)

Setter for CollisionUseParent

    [Obsolete("SetCompatibilityMode is deprecated. Use the CompatibilityMode property instead.")]
    public void SetCompatibilityMode(bool enable)

Setter for CompatibilityMode

    [Obsolete("SetCustomTransform is deprecated. Use the CellCustomTransform property instead.")]
    public void SetCustomTransform(Transform2D customTransform)

Setter for CellCustomTransform

    [Obsolete("SetHalfOffset is deprecated. Use the CellHalfOffset property instead.")]
    public void SetHalfOffset(HalfOffset halfOffset)

Setter for CellHalfOffset

    [Obsolete("SetMode is deprecated. Use the Mode property instead.")]
    public void SetMode(ModeEnum mode)

Setter for Mode

    [Obsolete("SetOccluderLightMask is deprecated. Use the OccluderLightMask property instead.")]
    public void SetOccluderLightMask(int mask)

Setter for OccluderLightMask

    [Obsolete("SetQuadrantSize is deprecated. Use the CellQuadrantSize property instead.")]
    public void SetQuadrantSize(int size)

Setter for CellQuadrantSize

    [Obsolete("SetTileOrigin is deprecated. Use the CellTileOrigin property instead.")]
    public void SetTileOrigin(TileOrigin origin)

Setter for CellTileOrigin

    [Obsolete("SetTileset is deprecated. Use the TileSet property instead.")]
    public void SetTileset(TileSet tileset)

Setter for TileSet

    [Obsolete("SetYSortMode is deprecated. Use the CellYSort property instead.")]
    public void SetYSortMode(bool enable)

Setter for CellYSort

    public void UpdateBitmaskArea(Vector2 position)

Applies autotiling rules to the cell (and its adjacent cells) referenced by its grid-based X and Y coordinates.

    public void UpdateBitmaskRegion(Vector2? start = default(Vector2?), Vector2? end = default(Vector2?))

Applies autotiling rules to the cells in the given region (specified by grid-based X and Y coordinates).

Calling with invalid (or missing) parameters applies autotiling rules for the entire tilemap.

    public void UpdateDirtyQuadrants()

Updates the tile map’s quadrants, allowing things such as navigation and collision shapes to be immediately used if modified.

    public Vector2 WorldToMap(Vector2 worldPosition)

Returns the tilemap (grid-based) coordinates corresponding to the given local position.

Inner Types

HalfOffset

Name Value Description
X 0 Half offset on the X coordinate.
Y 1 Half offset on the Y coordinate.
Disabled 2 Half offset disabled.
NegativeX 3 Half offset on the X coordinate (negative).
NegativeY 4 Half offset on the Y coordinate (negative).

ModeEnum

Name Value Description
Square 0 Orthogonal orientation mode.
Isometric 1 Isometric orientation mode.
Custom 2 Custom orientation mode.

TileOrigin

Name Value Description
TopLeft 0 Tile origin at its top-left corner.
Center 1 Tile origin at its center.
BottomLeft 2 Tile origin at its bottom-left corner.
Tags: