Struct TileMap

Node for 2D tile-based maps.

struct TileMap ;

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.

Properties

NameTypeDescription
cellClipUv[get, set] boolIf true, the cell's UVs will be clipped.
cellCustomTransform[get, set] Transform2DThe custom Transform2D to be applied to the TileMap's cells.
cellHalfOffset[get, set] TileMap.HalfOffsetAmount to offset alternating tiles. See halfoffset for possible values.
cellQuadrantSize[get, set] longThe TileMap's quadrant size. Optimizes drawing by batching, using chunks of this size.
cellSize[get, set] Vector2The TileMap's cell size.
cellTileOrigin[get, set] TileMap.TileOriginPosition for tile origin. See tileorigin for possible values.
cellYSort[get, set] boolIf true, the TileMap's children will be drawn in order of their Y coordinate.
centeredTextures[get, set] boolIf 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.
collisionBounce[get, set] doubleBounce value for static body collisions (see collision_use_kinematic).
collisionFriction[get, set] doubleFriction value for static body collisions (see collision_use_kinematic).
collisionLayer[get, set] longThe collision layer(s) for all colliders in the TileMap.
collisionMask[get, set] longThe collision mask(s) for all colliders in the TileMap.
collisionUseKinematic[get, set] boolIf true, TileMap collisions will be handled as a kinematic body. If false, collisions will be handled as static body.
collisionUseParent[get, set] boolIf true, this tilemap's collision shape will be added to the collision shape of the parent. The parent has to be a CollisionObject2D.
compatibilityMode[get, set] boolIf 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.
mode[get, set] TileMap.ModeThe TileMap orientation mode. See mode for possible values.
occluderLightMask[get, set] longThe 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).
tileSet[get, set] TileSetThe assigned TileSet.

Methods

NameDescription
_clearQuadrants
_getOldCellSize
_getTileData
_recreateQuadrants
_setCelld
_setOldCellSize
_setTileData
clear Clears all cells.
fixInvalidTiles Clears cells that do not exist in the tileset.
getCell Returns the tile index of the given cell. If no tile exists in the cell, returns constant INVALID_CELL.
getCellAutotileCoord Returns the coordinate of the autotile variation in the tileset. Returns a zero vector if the cell doesn't have autotiling.
getCellSize
getCellv Returns the tile index of the cell given by a Vector2. If no tile exists in the cell, returns constant INVALID_CELL.
getClipUv
getCollisionBounce
getCollisionFriction
getCollisionLayer
getCollisionLayerBit Returns true if the given collision layer bit is set.
getCollisionMask
getCollisionMaskBit Returns true if the given collision mask bit is set.
getCollisionUseKinematic
getCollisionUseParent
getCustomTransform
getHalfOffset
getMode
getOccluderLightMask
getQuadrantSize
getTileOrigin
getTileset
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).
getUsedCellsById Returns an array of all cells with the given tile id.
getUsedRect Returns a rectangle enclosing the used (non-empty) tiles of the map.
isCellTransposed Returns true if the given cell is transposed, i.e. the X and Y axes are swapped.
isCellXFlipped Returns true if the given cell is flipped in the X axis.
isCellYFlipped Returns true if the given cell is flipped in the Y axis.
isCenteredTexturesEnabled
isCompatibilityModeEnabled
isYSortModeEnabled
mapToWorld Returns the global position corresponding to the given tilemap (grid-based) coordinates. Optionally, the tilemap's half offset can be ignored.
setCell 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:
setCellSize
setCellv 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.
setCenteredTextures
setClipUv
setCollisionBounce
setCollisionFriction
setCollisionLayer
setCollisionLayerBit Sets the given collision layer bit.
setCollisionMask
setCollisionMaskBit Sets the given collision mask bit.
setCollisionUseKinematic
setCollisionUseParent
setCompatibilityMode
setCustomTransform
setHalfOffset
setMode
setOccluderLightMask
setQuadrantSize
setTileOrigin
setTileset
setYSortMode
updateBitmaskArea Applies autotiling rules to the cell (and its adjacent cells) referenced by its grid-based X and Y coordinates.
updateBitmaskRegion 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.
updateDirtyQuadrants Updates the tile map's quadrants, allowing things such as navigation and collision shapes to be immediately used if modified.
worldToMap Returns the tilemap (grid-based) coordinates corresponding to the given local position.

Enums

NameDescription
Constants
HalfOffset
Mode
TileOrigin