:github_url: hide .. Generated automatically by doc/tools/makerst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the TileMap.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_TileMap: TileMap ======= **Inherits:** :ref:`Node2D` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` **Category:** Core Brief Description ----------------- Node for 2D tile-based maps. Properties ---------- +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`cell_clip_uv` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`Transform2D` | :ref:`cell_custom_transform` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`HalfOffset` | :ref:`cell_half_offset` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`int` | :ref:`cell_quadrant_size` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`cell_size` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`TileOrigin` | :ref:`cell_tile_origin` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`cell_y_sort` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`float` | :ref:`collision_bounce` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`float` | :ref:`collision_friction` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`int` | :ref:`collision_layer` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`int` | :ref:`collision_mask` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`collision_use_kinematic` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`Mode` | :ref:`mode` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`int` | :ref:`occluder_light_mask` | +--------------------------------------------+--------------------------------------------------------------------------------+ | :ref:`TileSet` | :ref:`tile_set` | +--------------------------------------------+--------------------------------------------------------------------------------+ Methods ------- +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`fix_invalid_tiles` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_cell` **(** :ref:`int` x, :ref:`int` y **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_cell_autotile_coord` **(** :ref:`int` x, :ref:`int` y **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_cellv` **(** :ref:`Vector2` position **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`get_collision_layer_bit` **(** :ref:`int` bit **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`get_collision_mask_bit` **(** :ref:`int` bit **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_used_cells` **(** **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_used_cells_by_id` **(** :ref:`int` id **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`get_used_rect` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_cell_transposed` **(** :ref:`int` x, :ref:`int` y **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_cell_x_flipped` **(** :ref:`int` x, :ref:`int` y **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_cell_y_flipped` **(** :ref:`int` x, :ref:`int` y **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`map_to_world` **(** :ref:`Vector2` map_position, :ref:`bool` ignore_half_ofs=false **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_cell` **(** :ref:`int` x, :ref:`int` y, :ref:`int` tile, :ref:`bool` flip_x=false, :ref:`bool` flip_y=false, :ref:`bool` transpose=false, :ref:`Vector2` autotile_coord=Vector2( 0, 0 ) **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_cellv` **(** :ref:`Vector2` position, :ref:`int` tile, :ref:`bool` flip_x=false, :ref:`bool` flip_y=false, :ref:`bool` transpose=false **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_collision_layer_bit` **(** :ref:`int` bit, :ref:`bool` value **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_collision_mask_bit` **(** :ref:`int` bit, :ref:`bool` value **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`update_bitmask_area` **(** :ref:`Vector2` position **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`update_bitmask_region` **(** :ref:`Vector2` start=Vector2( 0, 0 ), :ref:`Vector2` end=Vector2( 0, 0 ) **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`update_dirty_quadrants` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`world_to_map` **(** :ref:`Vector2` world_position **)** const | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Signals ------- .. _class_TileMap_signal_settings_changed: - **settings_changed** **(** **)** Emitted when a tilemap setting has changed. Enumerations ------------ .. _enum_TileMap_Mode: .. _class_TileMap_constant_MODE_SQUARE: .. _class_TileMap_constant_MODE_ISOMETRIC: .. _class_TileMap_constant_MODE_CUSTOM: enum **Mode**: - **MODE_SQUARE** = **0** --- Orthogonal orientation mode. - **MODE_ISOMETRIC** = **1** --- Isometric orientation mode. - **MODE_CUSTOM** = **2** --- Custom orientation mode. ---- .. _enum_TileMap_HalfOffset: .. _class_TileMap_constant_HALF_OFFSET_X: .. _class_TileMap_constant_HALF_OFFSET_Y: .. _class_TileMap_constant_HALF_OFFSET_DISABLED: .. _class_TileMap_constant_HALF_OFFSET_NEGATIVE_X: .. _class_TileMap_constant_HALF_OFFSET_NEGATIVE_Y: enum **HalfOffset**: - **HALF_OFFSET_X** = **0** --- Half offset on the X coordinate. - **HALF_OFFSET_Y** = **1** --- Half offset on the Y coordinate. - **HALF_OFFSET_DISABLED** = **2** --- Half offset disabled. - **HALF_OFFSET_NEGATIVE_X** = **3** --- Half offset on the X coordinate (negative). - **HALF_OFFSET_NEGATIVE_Y** = **4** --- Half offset on the Y coordinate (negative). ---- .. _enum_TileMap_TileOrigin: .. _class_TileMap_constant_TILE_ORIGIN_TOP_LEFT: .. _class_TileMap_constant_TILE_ORIGIN_CENTER: .. _class_TileMap_constant_TILE_ORIGIN_BOTTOM_LEFT: enum **TileOrigin**: - **TILE_ORIGIN_TOP_LEFT** = **0** --- Tile origin at its top-left corner. - **TILE_ORIGIN_CENTER** = **1** --- Tile origin at its center. - **TILE_ORIGIN_BOTTOM_LEFT** = **2** --- Tile origin at its bottom-left corner. Constants --------- .. _class_TileMap_constant_INVALID_CELL: - **INVALID_CELL** = **-1** --- Returned when a cell doesn't exist. Description ----------- Node for 2D tile-based maps. Tilemaps use a :ref:`TileSet` which contain a list of tiles (textures plus optional collision, navigation, and/or occluder shapes) which are used to create grid-based maps. Tutorials --------- - :doc:`../tutorials/2d/using_tilemaps` Property Descriptions --------------------- .. _class_TileMap_property_cell_clip_uv: - :ref:`bool` **cell_clip_uv** +----------+--------------------+ | *Setter* | set_clip_uv(value) | +----------+--------------------+ | *Getter* | get_clip_uv() | +----------+--------------------+ ---- .. _class_TileMap_property_cell_custom_transform: - :ref:`Transform2D` **cell_custom_transform** +----------+-----------------------------+ | *Setter* | set_custom_transform(value) | +----------+-----------------------------+ | *Getter* | get_custom_transform() | +----------+-----------------------------+ The custom :ref:`Transform2D` to be applied to the TileMap's cells. ---- .. _class_TileMap_property_cell_half_offset: - :ref:`HalfOffset` **cell_half_offset** +----------+------------------------+ | *Setter* | set_half_offset(value) | +----------+------------------------+ | *Getter* | get_half_offset() | +----------+------------------------+ Amount to offset alternating tiles. Uses HALF_OFFSET\_\* constants. Default value: HALF_OFFSET_DISABLED. ---- .. _class_TileMap_property_cell_quadrant_size: - :ref:`int` **cell_quadrant_size** +----------+--------------------------+ | *Setter* | set_quadrant_size(value) | +----------+--------------------------+ | *Getter* | get_quadrant_size() | +----------+--------------------------+ The TileMap's quadrant size. Optimizes drawing by batching, using chunks of this size. Default value: 16. ---- .. _class_TileMap_property_cell_size: - :ref:`Vector2` **cell_size** +----------+----------------------+ | *Setter* | set_cell_size(value) | +----------+----------------------+ | *Getter* | get_cell_size() | +----------+----------------------+ The TileMap's cell size. ---- .. _class_TileMap_property_cell_tile_origin: - :ref:`TileOrigin` **cell_tile_origin** +----------+------------------------+ | *Setter* | set_tile_origin(value) | +----------+------------------------+ | *Getter* | get_tile_origin() | +----------+------------------------+ Position for tile origin. Uses TILE_ORIGIN\_\* constants. Default value: TILE_ORIGIN_TOP_LEFT. ---- .. _class_TileMap_property_cell_y_sort: - :ref:`bool` **cell_y_sort** +----------+--------------------------+ | *Setter* | set_y_sort_mode(value) | +----------+--------------------------+ | *Getter* | is_y_sort_mode_enabled() | +----------+--------------------------+ If ``true``, the TileMap's children will be drawn in order of their Y coordinate. Default value: ``false``. ---- .. _class_TileMap_property_collision_bounce: - :ref:`float` **collision_bounce** +----------+-----------------------------+ | *Setter* | set_collision_bounce(value) | +----------+-----------------------------+ | *Getter* | get_collision_bounce() | +----------+-----------------------------+ Bounce value for static body collisions (see ``collision_use_kinematic``). Default value: 0. ---- .. _class_TileMap_property_collision_friction: - :ref:`float` **collision_friction** +----------+-------------------------------+ | *Setter* | set_collision_friction(value) | +----------+-------------------------------+ | *Getter* | get_collision_friction() | +----------+-------------------------------+ Friction value for static body collisions (see ``collision_use_kinematic``). Default value: 1. ---- .. _class_TileMap_property_collision_layer: - :ref:`int` **collision_layer** +----------+----------------------------+ | *Setter* | set_collision_layer(value) | +----------+----------------------------+ | *Getter* | get_collision_layer() | +----------+----------------------------+ The collision layer(s) for all colliders in the TileMap. ---- .. _class_TileMap_property_collision_mask: - :ref:`int` **collision_mask** +----------+---------------------------+ | *Setter* | set_collision_mask(value) | +----------+---------------------------+ | *Getter* | get_collision_mask() | +----------+---------------------------+ The collision mask(s) for all colliders in the TileMap. ---- .. _class_TileMap_property_collision_use_kinematic: - :ref:`bool` **collision_use_kinematic** +----------+------------------------------------+ | *Setter* | set_collision_use_kinematic(value) | +----------+------------------------------------+ | *Getter* | get_collision_use_kinematic() | +----------+------------------------------------+ If ``true``, TileMap collisions will be handled as a kinematic body. If ``false``, collisions will be handled as static body. Default value: ``false``. ---- .. _class_TileMap_property_mode: - :ref:`Mode` **mode** +----------+-----------------+ | *Setter* | set_mode(value) | +----------+-----------------+ | *Getter* | get_mode() | +----------+-----------------+ The TileMap orientation mode. Uses MODE\_\* constants. Default value: MODE_SQUARE. ---- .. _class_TileMap_property_occluder_light_mask: - :ref:`int` **occluder_light_mask** +----------+--------------------------------+ | *Setter* | set_occluder_light_mask(value) | +----------+--------------------------------+ | *Getter* | get_occluder_light_mask() | +----------+--------------------------------+ 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). ---- .. _class_TileMap_property_tile_set: - :ref:`TileSet` **tile_set** +----------+--------------------+ | *Setter* | set_tileset(value) | +----------+--------------------+ | *Getter* | get_tileset() | +----------+--------------------+ The assigned :ref:`TileSet`. Method Descriptions ------------------- .. _class_TileMap_method_clear: - void **clear** **(** **)** Clears all cells. ---- .. _class_TileMap_method_fix_invalid_tiles: - void **fix_invalid_tiles** **(** **)** Clears cells that do not exist in the tileset. ---- .. _class_TileMap_method_get_cell: - :ref:`int` **get_cell** **(** :ref:`int` x, :ref:`int` y **)** const Returns the tile index of the given cell. If no tile exists in the cell, returns :ref:`INVALID_CELL`. ---- .. _class_TileMap_method_get_cell_autotile_coord: - :ref:`Vector2` **get_cell_autotile_coord** **(** :ref:`int` x, :ref:`int` y **)** const ---- .. _class_TileMap_method_get_cellv: - :ref:`int` **get_cellv** **(** :ref:`Vector2` position **)** const Returns the tile index of the cell given by a Vector2. If no tile exists in the cell, returns :ref:`INVALID_CELL`. ---- .. _class_TileMap_method_get_collision_layer_bit: - :ref:`bool` **get_collision_layer_bit** **(** :ref:`int` bit **)** const Returns ``true`` if the given collision layer bit is set. ---- .. _class_TileMap_method_get_collision_mask_bit: - :ref:`bool` **get_collision_mask_bit** **(** :ref:`int` bit **)** const Returns ``true`` if the given collision mask bit is set. ---- .. _class_TileMap_method_get_used_cells: - :ref:`Array` **get_used_cells** **(** **)** const Returns a :ref:`Vector2` array with the positions of all cells containing a tile from the tileset (i.e. a tile index different from ``-1``). ---- .. _class_TileMap_method_get_used_cells_by_id: - :ref:`Array` **get_used_cells_by_id** **(** :ref:`int` id **)** const Returns an array of all cells with the given tile id. ---- .. _class_TileMap_method_get_used_rect: - :ref:`Rect2` **get_used_rect** **(** **)** Returns a rectangle enclosing the used (non-empty) tiles of the map. ---- .. _class_TileMap_method_is_cell_transposed: - :ref:`bool` **is_cell_transposed** **(** :ref:`int` x, :ref:`int` y **)** const Returns ``true`` if the given cell is transposed, i.e. the x and y axes are swapped. ---- .. _class_TileMap_method_is_cell_x_flipped: - :ref:`bool` **is_cell_x_flipped** **(** :ref:`int` x, :ref:`int` y **)** const Returns ``true`` if the given cell is flipped in the x axis. ---- .. _class_TileMap_method_is_cell_y_flipped: - :ref:`bool` **is_cell_y_flipped** **(** :ref:`int` x, :ref:`int` y **)** const Returns ``true`` if the given cell is flipped in the y axis. ---- .. _class_TileMap_method_map_to_world: - :ref:`Vector2` **map_to_world** **(** :ref:`Vector2` map_position, :ref:`bool` ignore_half_ofs=false **)** const Returns the global position corresponding to the given tilemap (grid-based) coordinates. Optionally, the tilemap's half offset can be ignored. ---- .. _class_TileMap_method_set_cell: - void **set_cell** **(** :ref:`int` x, :ref:`int` y, :ref:`int` tile, :ref:`bool` flip_x=false, :ref:`bool` flip_y=false, :ref:`bool` transpose=false, :ref:`Vector2` autotile_coord=Vector2( 0, 0 ) **)** 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 :ref:`update_dirty_quadrants`. ---- .. _class_TileMap_method_set_cellv: - void **set_cellv** **(** :ref:`Vector2` position, :ref:`int` tile, :ref:`bool` flip_x=false, :ref:`bool` flip_y=false, :ref:`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 :ref:`update_dirty_quadrants`. ---- .. _class_TileMap_method_set_collision_layer_bit: - void **set_collision_layer_bit** **(** :ref:`int` bit, :ref:`bool` value **)** Sets the given collision layer bit. ---- .. _class_TileMap_method_set_collision_mask_bit: - void **set_collision_mask_bit** **(** :ref:`int` bit, :ref:`bool` value **)** Sets the given collision mask bit. ---- .. _class_TileMap_method_update_bitmask_area: - void **update_bitmask_area** **(** :ref:`Vector2` position **)** Applies autotiling rules to the cell (and its adjacent cells) referenced by its grid-based x and y coordinates. ---- .. _class_TileMap_method_update_bitmask_region: - void **update_bitmask_region** **(** :ref:`Vector2` start=Vector2( 0, 0 ), :ref:`Vector2` end=Vector2( 0, 0 ) **)** 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. ---- .. _class_TileMap_method_update_dirty_quadrants: - void **update_dirty_quadrants** **(** **)** Updates the tile map's quadrants, allowing things such as navigation and collision shapes to be immediately used if modified. ---- .. _class_TileMap_method_world_to_map: - :ref:`Vector2` **world_to_map** **(** :ref:`Vector2` world_position **)** const Returns the tilemap (grid-based) coordinates corresponding to the given local position.