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. Uses HALF_OFFSET_* constants. Default value: HALF_OFFSET_DISABLED.

    public int CellQuadrantSize { get; set; }

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

    public Vector2 CellSize { get; set; }

The TileMap’s cell size.

    public TileOrigin CellTileOrigin { get; set; }

Position for tile origin. Uses TILE_ORIGIN_* constants. Default value: TILE_ORIGIN_TOP_LEFT.

    public bool CellYSort { get; set; }

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

    public float CollisionBounce { get; set; }

Bounce value for static body collisions (see collision_use_kinematic). Default value: 0.

    public float CollisionFriction { get; set; }

Friction value for static body collisions (see collision_use_kinematic). Default value: 1.

    public int CollisionLayer { get; set; }

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

    public int 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. Default value: false.

    public ModeEnum Mode { get; set; }

The TileMap orientation mode. Uses MODE_* constants. Default value: MODE_SQUARE.

    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)

    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].

    public bool GetClipUv()

Getter for CellClipUv

    public float GetCollisionBounce()

Getter for CollisionBounce

    public float GetCollisionFriction()

Getter for CollisionFriction

    public int GetCollisionLayer()

Getter for CollisionLayer

    public bool GetCollisionLayerBit(int bit)

Returns true if the given collision layer bit is set.

    public int GetCollisionMask()

Getter for CollisionMask

    public bool GetCollisionMaskBit(int bit)

Returns true if the given collision mask bit is set.

    public bool GetCollisionUseKinematic()

Getter for CollisionUseKinematic

    public Transform2D GetCustomTransform()

Getter for CellCustomTransform

    public HalfOffset GetHalfOffset()

Getter for CellHalfOffset

    public ModeEnum GetMode()

Getter for Mode

    public int GetOccluderLightMask()

Getter for OccluderLightMask

    public int GetQuadrantSize()

Getter for CellQuadrantSize

    public TileOrigin GetTileOrigin()

Getter for CellTileOrigin

    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.

    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 that 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().

    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 that 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().

    public void SetClipUv(bool enable)

Setter for CellClipUv

    public void SetCollisionBounce(float value)

Setter for CollisionBounce

    public void SetCollisionFriction(float value)

Setter for CollisionFriction

    public void SetCollisionLayer(int layer)

Setter for CollisionLayer

    public void SetCollisionLayerBit(int bit, bool value)

Sets the given collision layer bit.

    public void SetCollisionMask(int mask)

Setter for CollisionMask

    public void SetCollisionMaskBit(int bit, bool value)

Sets the given collision mask bit.

    public void SetCollisionUseKinematic(bool useKinematic)

Setter for CollisionUseKinematic

    public void SetCustomTransform(Transform2D customTransform)

Setter for CellCustomTransform

    public void SetHalfOffset(HalfOffset halfOffset)

Setter for CellHalfOffset

    public void SetMode(ModeEnum mode)

Setter for Mode

    public void SetOccluderLightMask(int mask)

Setter for OccluderLightMask

    public void SetQuadrantSize(int size)

Setter for CellQuadrantSize

    public void SetTileOrigin(TileOrigin origin)

Setter for CellTileOrigin

    public void SetTileset(TileSet tileset)

Setter for TileSet

    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.

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: