TileMap

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. When doing physics queries against the tilemap, the cell coordinates are encoded as metadata for each detected collision shape returned by methods such as Physics2DDirectSpaceState.intersectShape, Physics2DDirectBodyState.getContactColliderShapeMetadata, etc.

@GodotBaseClass
struct TileMap {}

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

Constants
enum Constants
HalfOffset
enum HalfOffset
Mode
enum Mode
TileOrigin
enum TileOrigin

Functions

_clearQuadrants
void _clearQuadrants()
_getOldCellSize
long _getOldCellSize()
_getTileData
PoolIntArray _getTileData()
_recreateQuadrants
void _recreateQuadrants()
_setCelld
void _setCelld(Vector2 position, Dictionary data)
_setOldCellSize
void _setOldCellSize(long size)
_setTileData
void _setTileData(PoolIntArray arg0)
clear
void clear()

Clears all cells.

fixInvalidTiles
void fixInvalidTiles()

Clears cells that do not exist in the tileset.

getCell
long getCell(long x, long y)

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

getCellAutotileCoord
Vector2 getCellAutotileCoord(long x, long y)

Returns the coordinate (subtile column and row) of the autotile variation in the tileset. Returns a zero vector if the cell doesn't have autotiling.

getCellSize
Vector2 getCellSize()
getCellv
long 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.

getClipUv
bool getClipUv()
getCollisionBounce
double getCollisionBounce()
getCollisionFriction
double getCollisionFriction()
getCollisionLayer
long getCollisionLayer()
getCollisionLayerBit
bool getCollisionLayerBit(long bit)

Returns true if the given collision layer bit is set.

getCollisionMask
long getCollisionMask()
getCollisionMaskBit
bool getCollisionMaskBit(long bit)

Returns true if the given collision mask bit is set.

getCollisionUseKinematic
bool getCollisionUseKinematic()
getCollisionUseParent
bool getCollisionUseParent()
getCustomTransform
Transform2D getCustomTransform()
getHalfOffset
TileMap.HalfOffset getHalfOffset()
getMode
TileMap.Mode getMode()
getOccluderLightMask
long getOccluderLightMask()
getQuadrantSize
long getQuadrantSize()
getTileOrigin
TileMap.TileOrigin getTileOrigin()
getTileset
Ref!TileSet getTileset()
getUsedCells
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).

getUsedCellsById
Array getUsedCellsById(long id)

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

getUsedRect
Rect2 getUsedRect()

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

isCellTransposed
bool isCellTransposed(long x, long y)

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

isCellXFlipped
bool isCellXFlipped(long x, long y)

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

isCellYFlipped
bool isCellYFlipped(long x, long y)

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

isCenteredTexturesEnabled
bool isCenteredTexturesEnabled()
isCompatibilityModeEnabled
bool isCompatibilityModeEnabled()
isShowCollisionEnabled
bool isShowCollisionEnabled()
isYSortModeEnabled
bool isYSortModeEnabled()
mapToWorld
Vector2 mapToWorld(Vector2 map_position, bool ignore_half_ofs)

Returns the local position of the top left corner of the cell corresponding to the given tilemap (grid-based) coordinates. To get the global position, use Node2D.toGlobal:

opAssign
typeof(null) opAssign(typeof(null) n)
opEquals
bool opEquals(TileMap other)
opEquals
bool opEquals(typeof(null) n)
setCell
void setCell(long x, long y, long tile, bool flip_x, bool flip_y, bool transpose, Vector2 autotile_coord)

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. The autotile coordinate refers to the column and row of the subtile. 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
void setCellSize(Vector2 size)
setCellv
void setCellv(Vector2 position, long tile, bool flip_x, bool flip_y, bool transpose)

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
void setCenteredTextures(bool enable)
setClipUv
void setClipUv(bool enable)
setCollisionBounce
void setCollisionBounce(double value)
setCollisionFriction
void setCollisionFriction(double value)
setCollisionLayer
void setCollisionLayer(long layer)
setCollisionLayerBit
void setCollisionLayerBit(long bit, bool value)

Sets the given collision layer bit.

setCollisionMask
void setCollisionMask(long mask)
setCollisionMaskBit
void setCollisionMaskBit(long bit, bool value)

Sets the given collision mask bit.

setCollisionUseKinematic
void setCollisionUseKinematic(bool use_kinematic)
setCollisionUseParent
void setCollisionUseParent(bool use_parent)
setCompatibilityMode
void setCompatibilityMode(bool enable)
setCustomTransform
void setCustomTransform(Transform2D custom_transform)
setHalfOffset
void setHalfOffset(long half_offset)
setMode
void setMode(long mode)
setOccluderLightMask
void setOccluderLightMask(long mask)
setQuadrantSize
void setQuadrantSize(long size)
setShowCollision
void setShowCollision(bool enable)
setTileOrigin
void setTileOrigin(long origin)
setTileset
void setTileset(TileSet tileset)
setYSortMode
void setYSortMode(bool enable)
toHash
size_t toHash()
updateBitmaskArea
void updateBitmaskArea(Vector2 position)

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

updateBitmaskRegion
void updateBitmaskRegion(Vector2 start, Vector2 end)

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
void updateDirtyQuadrants()

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

worldToMap
Vector2 worldToMap(Vector2 world_position)

Returns the tilemap (grid-based) coordinates corresponding to the given local position. To use this with a global position, first determine the local position with Node2D.toLocal:

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Properties

cellClipUv
bool cellClipUv [@property getter]
bool cellClipUv [@property setter]

If true, the cell's UVs will be clipped.

cellCustomTransform
Transform2D cellCustomTransform [@property getter]
Transform2D cellCustomTransform [@property setter]

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

cellHalfOffset
TileMap.HalfOffset cellHalfOffset [@property getter]
long cellHalfOffset [@property setter]

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

cellQuadrantSize
long cellQuadrantSize [@property getter]
long cellQuadrantSize [@property setter]

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

cellSize
Vector2 cellSize [@property getter]
Vector2 cellSize [@property setter]

The TileMap's cell size.

cellTileOrigin
TileMap.TileOrigin cellTileOrigin [@property getter]
long cellTileOrigin [@property setter]

Position for tile origin. See tileorigin for possible values.

cellYSort
bool cellYSort [@property getter]
bool cellYSort [@property setter]

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

centeredTextures
bool centeredTextures [@property getter]
bool centeredTextures [@property setter]

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.

collisionBounce
double collisionBounce [@property getter]
double collisionBounce [@property setter]

Bounce value for static body collisions (see collision_use_kinematic).

collisionFriction
double collisionFriction [@property getter]
double collisionFriction [@property setter]

Friction value for static body collisions (see collision_use_kinematic).

collisionLayer
long collisionLayer [@property getter]
long collisionLayer [@property setter]

The collision layer(s) for all colliders in the TileMap. See url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masksCollision layers and masks/url in the documentation for more information.

collisionMask
long collisionMask [@property getter]
long collisionMask [@property setter]

The collision mask(s) for all colliders in the TileMap. See url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masksCollision layers and masks/url in the documentation for more information.

collisionUseKinematic
bool collisionUseKinematic [@property getter]
bool collisionUseKinematic [@property setter]

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

collisionUseParent
bool collisionUseParent [@property getter]
bool collisionUseParent [@property setter]

If true, this tilemap's collision shape will be added to the collision shape of the parent. The parent has to be a CollisionObject2D.

compatibilityMode
bool compatibilityMode [@property getter]
bool compatibilityMode [@property setter]

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.

mode
TileMap.Mode mode [@property getter]
long mode [@property setter]

The TileMap orientation mode. See mode for possible values.

occluderLightMask
long occluderLightMask [@property getter]
long occluderLightMask [@property setter]

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

showCollision
bool showCollision [@property getter]
bool showCollision [@property setter]

If true, collision shapes are visible in the editor. Doesn't affect collision shapes visibility at runtime. To show collision shapes at runtime, enable Visible Collision Shapes in the Debug menu instead.

tileSet
TileSet tileSet [@property getter]
TileSet tileSet [@property setter]

The assigned TileSet.

Static functions

_new
TileMap _new()

Construct a new instance of TileMap. Note: use memnew!TileMap instead.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

GDNativeClassBinding
struct GDNativeClassBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(ToRef) as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Meta