var changed: SimpleSignal
Emitted when this TileMapLayer
’s properties changes. This includes modified cells, properties, or changes made to its assigned TileSet
.
var collisionEnabled: Bool
Enable or disable collisions.
var collisionVisibilityMode: TileMapLayer.DebugVisibilityMode
Show or hide the TileMapLayer
’s collision shapes. If set to .default
, this depends on the show collision debug settings.
var enabled: Bool
If false
, disables this TileMapLayer
completely (rendering, collision, navigation, scene tiles, etc.)
var navigationEnabled: Bool
If true
, navigation regions are enabled.
var navigationVisibilityMode: TileMapLayer.DebugVisibilityMode
Show or hide the TileMapLayer
’s navigation meshes. If set to .default
, this depends on the show navigation debug settings.
var renderingQuadrantSize: Int32
The TileMapLayer
‘s quadrant size. A quadrant is a group of tiles to be drawn together on a single canvas item, for optimization purposes. renderingQuadrantSize
defines the length of a square’s side, in the map’s coordinate system, that forms the quadrant. Thus, the default quadrant size groups together 16 * 16 = 256
tiles.
var tileMapData: PackedByteArray
The raw tile map data as a byte array.
var tileSet: TileSet?
The TileSet
used by this layer. The textures, collisions, and additional behavior of all available tiles are stored here.
var useKinematicBodies: Bool
If true
, this TileMapLayer
collision shapes will be instantiated as kinematic bodies. This can be needed for moving TileMapLayer
nodes (i.e. moving platforms).
var xDrawOrderReversed: Bool
If ySortEnabled
is enabled, setting this to true
will reverse the order the tiles are drawn on the X-axis.
var ySortOrigin: Int32
This Y-sort origin value is added to each tile’s Y-sort origin value. This allows, for example, to fake a different height level. This can be useful for top-down view games.
func clear()
Clears all cells.
func eraseCell(coords: Vector2i)
Erases the cell at coordinates coords
.
func fixInvalidTiles()
Clears cells containing tiles that do not exist in the tileSet
.
func getCellAlternativeTile(coords: Vector2i) -> Int32
Returns the tile alternative ID of the cell at coordinates coords
.
func getCellAtlasCoords(Vector2i) -> Vector2i
Returns the tile atlas coordinates ID of the cell at coordinates coords
. Returns Vector2i(-1, -1)
if the cell does not exist.
func getCellSourceId(coords: Vector2i) -> Int32
Returns the tile source ID of the cell at coordinates coords
. Returns -1
if the cell does not exist.
func getCellTileData(coords: Vector2i) -> TileData?
Returns the TileData
object associated with the given cell, or null
if the cell does not exist or is not a TileSetAtlasSource
.
func getCoordsForBodyRid(body: RID) -> Vector2i
Returns the coordinates of the tile for given physics body RID
. Such an RID
can be retrieved from getColliderRid
, when colliding with a tile.
func getNavigationMap() -> RID
Returns the RID
of the NavigationServer2D
navigation used by this TileMapLayer
.
func getNeighborCell(coords: Vector2i, neighbor: TileSet.CellNeighbor) -> Vector2i
Returns the neighboring cell to the one at coordinates coords
, identified by the neighbor
direction. This method takes into account the different layouts a TileMap can take.
func getPattern(coordsArray: VariantCollection<Vector2i>) -> TileMapPattern?
Creates and returns a new TileMapPattern
from the given array of cells. See also setPattern(position:pattern:)
.
func getSurroundingCells(coords: Vector2i) -> VariantCollection<Vector2i>
Returns the list of all neighboring cells to the one at coords
.
func getUsedCells() -> VariantCollection<Vector2i>
Returns a Vector2i
array with the positions of all cells containing a tile. A cell is considered empty if its source identifier equals -1
, its atlas coordinate identifier is Vector2(-1, -1)
and its alternative identifier is -1
.
func getUsedCellsById(sourceId: Int32, atlasCoords: Vector2i, alternativeTile: Int32) -> VariantCollection<Vector2i>
Returns a Vector2i
array with the positions of all cells containing a tile. Tiles may be filtered according to their source (sourceId
), their atlas coordinates (atlasCoords
), or alternative id (alternativeTile
).
func getUsedRect() -> Rect2i
Returns a rectangle enclosing the used (non-empty) tiles of the map.
func hasBodyRid(body: RID) -> Bool
Returns whether the provided body
RID
belongs to one of this TileMapLayer
’s cells.
func localToMap(localPosition: Vector2) -> Vector2i
Returns the map coordinates of the cell containing the given localPosition
. If localPosition
is in global coordinates, consider using toLocal(globalPoint:)
before passing it to this method. See also mapToLocal(mapPosition:)
.
func mapPattern(positionInTilemap: Vector2i, coordsInPattern: Vector2i, pattern: TileMapPattern?) -> Vector2i
Returns for the given coordinates coordsInPattern
in a TileMapPattern
the corresponding cell coordinates if the pattern was pasted at the positionInTilemap
coordinates (see setPattern(position:pattern:)
). This mapping is required as in half-offset tile shapes, the mapping might not work by calculating position_in_tile_map + coords_in_pattern
.
func mapToLocal(mapPosition: Vector2i) -> Vector2
Returns the centered position of a cell in the TileMapLayer
’s local coordinate space. To convert the returned value into global coordinates, use toGlobal(localPoint:)
. See also localToMap(localPosition:)
.
func notifyRuntimeTileDataUpdate()
Notifies the TileMapLayer
node that calls to _useTileDataRuntimeUpdate(coords:)
or _tileDataRuntimeUpdate(coords:tileData:)
will lead to different results. This will thus trigger a TileMapLayer
update.
func setCell(coords: Vector2i, sourceId: Int32, atlasCoords: Vector2i, alternativeTile: Int32)
Sets the tile identifiers for the cell at coordinates coords
. Each tile of the TileSet
is identified using three parts:
func setCellsTerrainConnect(cells: VariantCollection<Vector2i>, terrainSet: Int32, terrain: Int32, ignoreEmptyTerrains: Bool)
Update all the cells in the cells
coordinates array so that they use the given terrain
for the given terrainSet
. If an updated cell has the same terrain as one of its neighboring cells, this function tries to join the two. This function might update neighboring tiles if needed to create correct terrain transitions.
func setCellsTerrainPath(VariantCollection<Vector2i>, terrainSet: Int32, terrain: Int32, ignoreEmptyTerrains: Bool)
Update all the cells in the path
coordinates array so that they use the given terrain
for the given terrainSet
. The function will also connect two successive cell in the path with the same terrain. This function might update neighboring tiles if needed to create correct terrain transitions.
func setNavigationMap(RID)
Sets a custom map
as a NavigationServer2D
navigation map. If not set, uses the default World2D
navigation map instead.
func setPattern(position: Vector2i, pattern: TileMapPattern?)
Pastes the TileMapPattern
at the given position
in the tile map. See also getPattern(coordsArray:)
.
func updateInternals()
Triggers a direct update of the TileMapLayer
. Usually, calling this function is not needed, as TileMapLayer
node updates automatically when one of its properties or cells is modified.