: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` Node for 2D tile-based maps. Description ----------- Node for 2D tile-based maps. Tilemaps use a :ref:`TileSet` which contain a list of tiles which are used to create grid-based maps. A TileMap may have several layers, layouting tiles on top of each other. Tutorials --------- - :doc:`../tutorials/2d/using_tilemaps` - `2D Platformer Demo `__ - `2D Isometric Demo `__ - `2D Hexagonal Demo `__ - `2D Navigation Astar Demo `__ - `2D Role Playing Game Demo `__ - `2D Kinematic Character Demo `__ Properties ---------- +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+ | :ref:`int` | :ref:`cell_quadrant_size` | ``16`` | +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+ | :ref:`bool` | :ref:`collision_animatable` | ``false`` | +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+ | :ref:`VisibilityMode` | :ref:`collision_visibility_mode` | ``0`` | +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+ | :ref:`VisibilityMode` | :ref:`navigation_visibility_mode` | ``0`` | +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+ | :ref:`TileSet` | :ref:`tile_set` | | +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+ Methods ------- +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_layer` **(** :ref:`int` to_position **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear` **(** **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear_layer` **(** :ref:`int` layer **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`fix_invalid_tiles` **(** **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_cell_alternative_tile` **(** :ref:`int` layer, :ref:`Vector2i` coords, :ref:`bool` use_proxies **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2i` | :ref:`get_cell_atlas_coords` **(** :ref:`int` layer, :ref:`Vector2i` coords, :ref:`bool` use_proxies **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_cell_source_id` **(** :ref:`int` layer, :ref:`Vector2i` coords, :ref:`bool` use_proxies **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2i` | :ref:`get_coords_for_body_rid` **(** :ref:`RID` body **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_layer_name` **(** :ref:`int` layer **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_layer_y_sort_origin` **(** :ref:`int` layer **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_layer_z_index` **(** :ref:`int` layer **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_layers_count` **(** **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2i` | :ref:`get_neighbor_cell` **(** :ref:`Vector2i` coords, :ref:`CellNeighbor` neighbor **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2i[]` | :ref:`get_surrounding_tiles` **(** :ref:`Vector2i` coords **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2i[]` | :ref:`get_used_cells` **(** :ref:`int` layer **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`get_used_rect` **(** **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_layer_enabled` **(** :ref:`int` layer **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_layer_y_sort_enabled` **(** :ref:`int` layer **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`map_to_world` **(** :ref:`Vector2i` map_position **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`move_layer` **(** :ref:`int` layer, :ref:`int` to_position **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_layer` **(** :ref:`int` layer **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_cell` **(** :ref:`int` layer, :ref:`Vector2i` coords, :ref:`int` source_id=-1, :ref:`Vector2i` atlas_coords=Vector2i(-1, -1), :ref:`int` alternative_tile=-1 **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_layer_enabled` **(** :ref:`int` layer, :ref:`bool` enabled **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_layer_name` **(** :ref:`int` layer, :ref:`String` name **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_layer_y_sort_enabled` **(** :ref:`int` layer, :ref:`bool` y_sort_enabled **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_layer_y_sort_origin` **(** :ref:`int` layer, :ref:`int` y_sort_origin **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_layer_z_index` **(** :ref:`int` layer, :ref:`int` z_index **)** | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2i` | :ref:`world_to_map` **(** :ref:`Vector2` world_position **)** |const| | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Signals ------- .. _class_TileMap_signal_changed: - **changed** **(** **)** Emitted when the :ref:`TileSet` of this TileMap changes. Enumerations ------------ .. _enum_TileMap_VisibilityMode: .. _class_TileMap_constant_VISIBILITY_MODE_DEFAULT: .. _class_TileMap_constant_VISIBILITY_MODE_FORCE_HIDE: .. _class_TileMap_constant_VISIBILITY_MODE_FORCE_SHOW: enum **VisibilityMode**: - **VISIBILITY_MODE_DEFAULT** = **0** --- Use the debug settings to determine visibility. - **VISIBILITY_MODE_FORCE_HIDE** = **2** --- Always hide. - **VISIBILITY_MODE_FORCE_SHOW** = **1** --- Always show. Property Descriptions --------------------- .. _class_TileMap_property_cell_quadrant_size: - :ref:`int` **cell_quadrant_size** +-----------+--------------------------+ | *Default* | ``16`` | +-----------+--------------------------+ | *Setter* | set_quadrant_size(value) | +-----------+--------------------------+ | *Getter* | get_quadrant_size() | +-----------+--------------------------+ The TileMap's quadrant size. Optimizes drawing by batching, using chunks of this size. ---- .. _class_TileMap_property_collision_animatable: - :ref:`bool` **collision_animatable** +-----------+---------------------------------+ | *Default* | ``false`` | +-----------+---------------------------------+ | *Setter* | set_collision_animatable(value) | +-----------+---------------------------------+ | *Getter* | is_collision_animatable() | +-----------+---------------------------------+ If enabled, the TileMap will see its collisions synced to the physics tick and change its collision type from static to kinematic. This is required to create TileMap-based moving platform. **Note:** Enabling ``collision_animatable`` may have a small performance impact, only do it if the TileMap is moving and has colliding tiles. ---- .. _class_TileMap_property_collision_visibility_mode: - :ref:`VisibilityMode` **collision_visibility_mode** +-----------+--------------------------------------+ | *Default* | ``0`` | +-----------+--------------------------------------+ | *Setter* | set_collision_visibility_mode(value) | +-----------+--------------------------------------+ | *Getter* | get_collision_visibility_mode() | +-----------+--------------------------------------+ Show or hide the TileMap's collision shapes. If set to ``VISIBILITY_MODE_DEFAULT``, this depends on the show collision debug settings. ---- .. _class_TileMap_property_navigation_visibility_mode: - :ref:`VisibilityMode` **navigation_visibility_mode** +-----------+---------------------------------------+ | *Default* | ``0`` | +-----------+---------------------------------------+ | *Setter* | set_navigation_visibility_mode(value) | +-----------+---------------------------------------+ | *Getter* | get_navigation_visibility_mode() | +-----------+---------------------------------------+ Show or hide the TileMap's collision shapes. If set to ``VISIBILITY_MODE_DEFAULT``, this depends on the show navigation debug settings. ---- .. _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_add_layer: - void **add_layer** **(** :ref:`int` to_position **)** Adds a layer at the given position ``to_position`` in the array. If ``to_position`` is -1, adds it at the end of the array. ---- .. _class_TileMap_method_clear: - void **clear** **(** **)** Clears all cells. ---- .. _class_TileMap_method_clear_layer: - void **clear_layer** **(** :ref:`int` layer **)** Clears all cells on the given layer. ---- .. _class_TileMap_method_fix_invalid_tiles: - void **fix_invalid_tiles** **(** **)** Clears cells that do not exist in the tileset. ---- .. _class_TileMap_method_get_cell_alternative_tile: - :ref:`int` **get_cell_alternative_tile** **(** :ref:`int` layer, :ref:`Vector2i` coords, :ref:`bool` use_proxies **)** |const| Returns the tile alternative ID of the cell on layer ``layer`` at ``coords``. If ``use_proxies`` is ``false``, ignores the :ref:`TileSet`'s tile proxies, returning the raw alternative identifier. See :ref:`TileSet.map_tile_proxy`. ---- .. _class_TileMap_method_get_cell_atlas_coords: - :ref:`Vector2i` **get_cell_atlas_coords** **(** :ref:`int` layer, :ref:`Vector2i` coords, :ref:`bool` use_proxies **)** |const| Returns the tile atlas coordinates ID of the cell on layer ``layer`` at coordinates ``coords``. If ``use_proxies`` is ``false``, ignores the :ref:`TileSet`'s tile proxies, returning the raw alternative identifier. See :ref:`TileSet.map_tile_proxy`. ---- .. _class_TileMap_method_get_cell_source_id: - :ref:`int` **get_cell_source_id** **(** :ref:`int` layer, :ref:`Vector2i` coords, :ref:`bool` use_proxies **)** |const| Returns the tile source ID of the cell on layer ``layer`` at coordinates ``coords``. If ``use_proxies`` is ``false``, ignores the :ref:`TileSet`'s tile proxies, returning the raw alternative identifier. See :ref:`TileSet.map_tile_proxy`. ---- .. _class_TileMap_method_get_coords_for_body_rid: - :ref:`Vector2i` **get_coords_for_body_rid** **(** :ref:`RID` body **)** Returns the coodinates of the tile for given physics body RID. Such RID can be retrieved from :ref:`KinematicCollision2D.get_collider_rid`, when colliding with a tile. ---- .. _class_TileMap_method_get_layer_name: - :ref:`String` **get_layer_name** **(** :ref:`int` layer **)** |const| Returns a TileMap layer's name. ---- .. _class_TileMap_method_get_layer_y_sort_origin: - :ref:`int` **get_layer_y_sort_origin** **(** :ref:`int` layer **)** |const| Returns a TileMap layer's Y sort origin. ---- .. _class_TileMap_method_get_layer_z_index: - :ref:`int` **get_layer_z_index** **(** :ref:`int` layer **)** |const| Returns a TileMap layer's Z-index value. ---- .. _class_TileMap_method_get_layers_count: - :ref:`int` **get_layers_count** **(** **)** |const| ---- .. _class_TileMap_method_get_neighbor_cell: - :ref:`Vector2i` **get_neighbor_cell** **(** :ref:`Vector2i` coords, :ref:`CellNeighbor` neighbor **)** |const| Returns the neighboring cell to the one at coordinates ``coords``, indentified by the ``neighbor`` direction. This method takes into account the different layouts a TileMap can take. ---- .. _class_TileMap_method_get_surrounding_tiles: - :ref:`Vector2i[]` **get_surrounding_tiles** **(** :ref:`Vector2i` coords **)** Returns the list of all neighbourings cells to the one at ``coords`` ---- .. _class_TileMap_method_get_used_cells: - :ref:`Vector2i[]` **get_used_cells** **(** :ref:`int` layer **)** |const| Returns a :ref:`Vector2` array with the positions of all cells containing a tile in the given layer. A cell is considered empty if its source identifier equals -1, its atlas coordinates identifiers is ``Vector2(-1, -1)`` and its alternative identifier is -1. ---- .. _class_TileMap_method_get_used_rect: - :ref:`Rect2` **get_used_rect** **(** **)** Returns a rectangle enclosing the used (non-empty) tiles of the map, including all layers. ---- .. _class_TileMap_method_is_layer_enabled: - :ref:`bool` **is_layer_enabled** **(** :ref:`int` layer **)** |const| Returns if a layer is enabled. ---- .. _class_TileMap_method_is_layer_y_sort_enabled: - :ref:`bool` **is_layer_y_sort_enabled** **(** :ref:`int` layer **)** |const| Returns if a layer Y-sorts its tiles. ---- .. _class_TileMap_method_map_to_world: - :ref:`Vector2` **map_to_world** **(** :ref:`Vector2i` map_position **)** |const| Returns the local position corresponding to the given tilemap (grid-based) coordinates. ---- .. _class_TileMap_method_move_layer: - void **move_layer** **(** :ref:`int` layer, :ref:`int` to_position **)** Moves the layer at index ``layer_index`` to the given position ``to_position`` in the array. ---- .. _class_TileMap_method_remove_layer: - void **remove_layer** **(** :ref:`int` layer **)** Moves the layer at index ``layer_index`` to the given position ``to_position`` in the array. ---- .. _class_TileMap_method_set_cell: - void **set_cell** **(** :ref:`int` layer, :ref:`Vector2i` coords, :ref:`int` source_id=-1, :ref:`Vector2i` atlas_coords=Vector2i(-1, -1), :ref:`int` alternative_tile=-1 **)** Sets the tile indentifiers for the cell on layer ``layer`` at coordinates ``coords``. Each tile of the :ref:`TileSet` is identified using three parts: - The source indentifier ``source_id`` identifies a :ref:`TileSetSource` identifier. See :ref:`TileSet.set_source_id`, - The atlas coordinates identifier ``atlas_coords`` identifies a tile coordinates in the atlas (if the source is a :ref:`TileSetAtlasSource`. For :ref:`TileSetScenesCollectionSource` it should be 0), - The alternative tile identifier ``alternative_tile`` identifies a tile alternative the source is a :ref:`TileSetAtlasSource`, and the scene for a :ref:`TileSetScenesCollectionSource`. ---- .. _class_TileMap_method_set_layer_enabled: - void **set_layer_enabled** **(** :ref:`int` layer, :ref:`bool` enabled **)** Enables or disables the layer ``layer``. A disabled layer is not processed at all (no rendering, no physics, etc...). ---- .. _class_TileMap_method_set_layer_name: - void **set_layer_name** **(** :ref:`int` layer, :ref:`String` name **)** Sets a layer's name. This is mostly useful in the editor. ---- .. _class_TileMap_method_set_layer_y_sort_enabled: - void **set_layer_y_sort_enabled** **(** :ref:`int` layer, :ref:`bool` y_sort_enabled **)** Enables or disables a layer's Y-sorting. If a layer is Y-sorted, the layer will behave as a CanvasItem node where each of its tile gets Y-sorted. Y-sorted layers should usually be on different Z-index values than not Y-sorted layers, otherwise, each of those layer will be Y-sorted as whole with the Y-sorted one. This is usually an undesired behvaior. ---- .. _class_TileMap_method_set_layer_y_sort_origin: - void **set_layer_y_sort_origin** **(** :ref:`int` layer, :ref:`int` y_sort_origin **)** Sets a layer's Y-sort origin value. 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 on each layer. This can be useful for top-down view games. ---- .. _class_TileMap_method_set_layer_z_index: - void **set_layer_z_index** **(** :ref:`int` layer, :ref:`int` z_index **)** Sets a layers Z-index value. This Z-index is added to each tile's Z-index value. ---- .. _class_TileMap_method_world_to_map: - :ref:`Vector2i` **world_to_map** **(** :ref:`Vector2` world_position **)** |const| Returns the tilemap (grid-based) coordinates corresponding to the given local position. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`