class_tilemap.rst 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. :github_url: hide
  2. .. meta::
  3. :keywords: gridmap
  4. .. DO NOT EDIT THIS FILE!!!
  5. .. Generated automatically from Godot engine sources.
  6. .. Generator: https://github.com/godotengine/godot/tree/4.3/doc/tools/make_rst.py.
  7. .. XML source: https://github.com/godotengine/godot/tree/4.3/doc/classes/TileMap.xml.
  8. .. _class_TileMap:
  9. TileMap
  10. =======
  11. **Deprecated:** Use multiple :ref:`TileMapLayer<class_TileMapLayer>` nodes instead. To convert a TileMap to a set of TileMapLayer nodes, open the TileMap bottom panel with the node selected, click the toolbox icon in the top-right corner and choose 'Extract TileMap layers as individual TileMapLayer nodes'.
  12. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  13. Node for 2D tile-based maps.
  14. .. rst-class:: classref-introduction-group
  15. Description
  16. -----------
  17. Node for 2D tile-based maps. Tilemaps use a :ref:`TileSet<class_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.
  18. For performance reasons, all TileMap updates are batched at the end of a frame. Notably, this means that scene tiles from a :ref:`TileSetScenesCollectionSource<class_TileSetScenesCollectionSource>` may be initialized after their parent. This is only queued when inside the scene tree.
  19. To force an update earlier on, call :ref:`update_internals<class_TileMap_method_update_internals>`.
  20. .. rst-class:: classref-introduction-group
  21. Tutorials
  22. ---------
  23. - :doc:`Using Tilemaps <../tutorials/2d/using_tilemaps>`
  24. - `2D Platformer Demo <https://godotengine.org/asset-library/asset/2727>`__
  25. - `2D Isometric Demo <https://godotengine.org/asset-library/asset/2718>`__
  26. - `2D Hexagonal Demo <https://godotengine.org/asset-library/asset/2717>`__
  27. - `2D Grid-based Navigation with AStarGrid2D Demo <https://godotengine.org/asset-library/asset/2723>`__
  28. - `2D Role Playing Game (RPG) Demo <https://godotengine.org/asset-library/asset/2729>`__
  29. - `2D Kinematic Character Demo <https://godotengine.org/asset-library/asset/2719>`__
  30. .. rst-class:: classref-reftable-group
  31. Properties
  32. ----------
  33. .. table::
  34. :widths: auto
  35. +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+
  36. | :ref:`bool<class_bool>` | :ref:`collision_animatable<class_TileMap_property_collision_animatable>` | ``false`` |
  37. +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+
  38. | :ref:`VisibilityMode<enum_TileMap_VisibilityMode>` | :ref:`collision_visibility_mode<class_TileMap_property_collision_visibility_mode>` | ``0`` |
  39. +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+
  40. | :ref:`VisibilityMode<enum_TileMap_VisibilityMode>` | :ref:`navigation_visibility_mode<class_TileMap_property_navigation_visibility_mode>` | ``0`` |
  41. +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+
  42. | :ref:`int<class_int>` | :ref:`rendering_quadrant_size<class_TileMap_property_rendering_quadrant_size>` | ``16`` |
  43. +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+
  44. | :ref:`TileSet<class_TileSet>` | :ref:`tile_set<class_TileMap_property_tile_set>` | |
  45. +----------------------------------------------------+--------------------------------------------------------------------------------------+-----------+
  46. .. rst-class:: classref-reftable-group
  47. Methods
  48. -------
  49. .. table::
  50. :widths: auto
  51. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | |void| | :ref:`_tile_data_runtime_update<class_TileMap_private_method__tile_data_runtime_update>`\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, tile_data\: :ref:`TileData<class_TileData>`\ ) |virtual| |
  53. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`bool<class_bool>` | :ref:`_use_tile_data_runtime_update<class_TileMap_private_method__use_tile_data_runtime_update>`\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`\ ) |virtual| |
  55. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | |void| | :ref:`add_layer<class_TileMap_method_add_layer>`\ (\ to_position\: :ref:`int<class_int>`\ ) |
  57. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | |void| | :ref:`clear<class_TileMap_method_clear>`\ (\ ) |
  59. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | |void| | :ref:`clear_layer<class_TileMap_method_clear_layer>`\ (\ layer\: :ref:`int<class_int>`\ ) |
  61. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | |void| | :ref:`erase_cell<class_TileMap_method_erase_cell>`\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`\ ) |
  63. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | |void| | :ref:`fix_invalid_tiles<class_TileMap_method_fix_invalid_tiles>`\ (\ ) |
  65. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | |void| | :ref:`force_update<class_TileMap_method_force_update>`\ (\ layer\: :ref:`int<class_int>` = -1\ ) |
  67. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`int<class_int>` | :ref:`get_cell_alternative_tile<class_TileMap_method_get_cell_alternative_tile>`\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, use_proxies\: :ref:`bool<class_bool>` = false\ ) |const| |
  69. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Vector2i<class_Vector2i>` | :ref:`get_cell_atlas_coords<class_TileMap_method_get_cell_atlas_coords>`\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, use_proxies\: :ref:`bool<class_bool>` = false\ ) |const| |
  71. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`int<class_int>` | :ref:`get_cell_source_id<class_TileMap_method_get_cell_source_id>`\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, use_proxies\: :ref:`bool<class_bool>` = false\ ) |const| |
  73. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`TileData<class_TileData>` | :ref:`get_cell_tile_data<class_TileMap_method_get_cell_tile_data>`\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, use_proxies\: :ref:`bool<class_bool>` = false\ ) |const| |
  75. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Vector2i<class_Vector2i>` | :ref:`get_coords_for_body_rid<class_TileMap_method_get_coords_for_body_rid>`\ (\ body\: :ref:`RID<class_RID>`\ ) |
  77. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`int<class_int>` | :ref:`get_layer_for_body_rid<class_TileMap_method_get_layer_for_body_rid>`\ (\ body\: :ref:`RID<class_RID>`\ ) |
  79. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`Color<class_Color>` | :ref:`get_layer_modulate<class_TileMap_method_get_layer_modulate>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  81. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`String<class_String>` | :ref:`get_layer_name<class_TileMap_method_get_layer_name>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  83. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`RID<class_RID>` | :ref:`get_layer_navigation_map<class_TileMap_method_get_layer_navigation_map>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  85. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`int<class_int>` | :ref:`get_layer_y_sort_origin<class_TileMap_method_get_layer_y_sort_origin>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  87. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`int<class_int>` | :ref:`get_layer_z_index<class_TileMap_method_get_layer_z_index>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  89. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`int<class_int>` | :ref:`get_layers_count<class_TileMap_method_get_layers_count>`\ (\ ) |const| |
  91. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`RID<class_RID>` | :ref:`get_navigation_map<class_TileMap_method_get_navigation_map>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  93. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`Vector2i<class_Vector2i>` | :ref:`get_neighbor_cell<class_TileMap_method_get_neighbor_cell>`\ (\ coords\: :ref:`Vector2i<class_Vector2i>`, neighbor\: :ref:`CellNeighbor<enum_TileSet_CellNeighbor>`\ ) |const| |
  95. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`TileMapPattern<class_TileMapPattern>` | :ref:`get_pattern<class_TileMap_method_get_pattern>`\ (\ layer\: :ref:`int<class_int>`, coords_array\: :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\]\ ) |
  97. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\] | :ref:`get_surrounding_cells<class_TileMap_method_get_surrounding_cells>`\ (\ coords\: :ref:`Vector2i<class_Vector2i>`\ ) |
  99. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\] | :ref:`get_used_cells<class_TileMap_method_get_used_cells>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  101. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\] | :ref:`get_used_cells_by_id<class_TileMap_method_get_used_cells_by_id>`\ (\ layer\: :ref:`int<class_int>`, source_id\: :ref:`int<class_int>` = -1, atlas_coords\: :ref:`Vector2i<class_Vector2i>` = Vector2i(-1, -1), alternative_tile\: :ref:`int<class_int>` = -1\ ) |const| |
  103. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`Rect2i<class_Rect2i>` | :ref:`get_used_rect<class_TileMap_method_get_used_rect>`\ (\ ) |const| |
  105. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`bool<class_bool>` | :ref:`is_layer_enabled<class_TileMap_method_is_layer_enabled>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  107. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`bool<class_bool>` | :ref:`is_layer_navigation_enabled<class_TileMap_method_is_layer_navigation_enabled>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  109. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`bool<class_bool>` | :ref:`is_layer_y_sort_enabled<class_TileMap_method_is_layer_y_sort_enabled>`\ (\ layer\: :ref:`int<class_int>`\ ) |const| |
  111. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`Vector2i<class_Vector2i>` | :ref:`local_to_map<class_TileMap_method_local_to_map>`\ (\ local_position\: :ref:`Vector2<class_Vector2>`\ ) |const| |
  113. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`Vector2i<class_Vector2i>` | :ref:`map_pattern<class_TileMap_method_map_pattern>`\ (\ position_in_tilemap\: :ref:`Vector2i<class_Vector2i>`, coords_in_pattern\: :ref:`Vector2i<class_Vector2i>`, pattern\: :ref:`TileMapPattern<class_TileMapPattern>`\ ) |
  115. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`Vector2<class_Vector2>` | :ref:`map_to_local<class_TileMap_method_map_to_local>`\ (\ map_position\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
  117. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | |void| | :ref:`move_layer<class_TileMap_method_move_layer>`\ (\ layer\: :ref:`int<class_int>`, to_position\: :ref:`int<class_int>`\ ) |
  119. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | |void| | :ref:`notify_runtime_tile_data_update<class_TileMap_method_notify_runtime_tile_data_update>`\ (\ layer\: :ref:`int<class_int>` = -1\ ) |
  121. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | |void| | :ref:`remove_layer<class_TileMap_method_remove_layer>`\ (\ layer\: :ref:`int<class_int>`\ ) |
  123. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | |void| | :ref:`set_cell<class_TileMap_method_set_cell>`\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, source_id\: :ref:`int<class_int>` = -1, atlas_coords\: :ref:`Vector2i<class_Vector2i>` = Vector2i(-1, -1), alternative_tile\: :ref:`int<class_int>` = 0\ ) |
  125. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | |void| | :ref:`set_cells_terrain_connect<class_TileMap_method_set_cells_terrain_connect>`\ (\ layer\: :ref:`int<class_int>`, cells\: :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\], terrain_set\: :ref:`int<class_int>`, terrain\: :ref:`int<class_int>`, ignore_empty_terrains\: :ref:`bool<class_bool>` = true\ ) |
  127. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | |void| | :ref:`set_cells_terrain_path<class_TileMap_method_set_cells_terrain_path>`\ (\ layer\: :ref:`int<class_int>`, path\: :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\], terrain_set\: :ref:`int<class_int>`, terrain\: :ref:`int<class_int>`, ignore_empty_terrains\: :ref:`bool<class_bool>` = true\ ) |
  129. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | |void| | :ref:`set_layer_enabled<class_TileMap_method_set_layer_enabled>`\ (\ layer\: :ref:`int<class_int>`, enabled\: :ref:`bool<class_bool>`\ ) |
  131. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | |void| | :ref:`set_layer_modulate<class_TileMap_method_set_layer_modulate>`\ (\ layer\: :ref:`int<class_int>`, modulate\: :ref:`Color<class_Color>`\ ) |
  133. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | |void| | :ref:`set_layer_name<class_TileMap_method_set_layer_name>`\ (\ layer\: :ref:`int<class_int>`, name\: :ref:`String<class_String>`\ ) |
  135. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | |void| | :ref:`set_layer_navigation_enabled<class_TileMap_method_set_layer_navigation_enabled>`\ (\ layer\: :ref:`int<class_int>`, enabled\: :ref:`bool<class_bool>`\ ) |
  137. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | |void| | :ref:`set_layer_navigation_map<class_TileMap_method_set_layer_navigation_map>`\ (\ layer\: :ref:`int<class_int>`, map\: :ref:`RID<class_RID>`\ ) |
  139. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. | |void| | :ref:`set_layer_y_sort_enabled<class_TileMap_method_set_layer_y_sort_enabled>`\ (\ layer\: :ref:`int<class_int>`, y_sort_enabled\: :ref:`bool<class_bool>`\ ) |
  141. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  142. | |void| | :ref:`set_layer_y_sort_origin<class_TileMap_method_set_layer_y_sort_origin>`\ (\ layer\: :ref:`int<class_int>`, y_sort_origin\: :ref:`int<class_int>`\ ) |
  143. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  144. | |void| | :ref:`set_layer_z_index<class_TileMap_method_set_layer_z_index>`\ (\ layer\: :ref:`int<class_int>`, z_index\: :ref:`int<class_int>`\ ) |
  145. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  146. | |void| | :ref:`set_navigation_map<class_TileMap_method_set_navigation_map>`\ (\ layer\: :ref:`int<class_int>`, map\: :ref:`RID<class_RID>`\ ) |
  147. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  148. | |void| | :ref:`set_pattern<class_TileMap_method_set_pattern>`\ (\ layer\: :ref:`int<class_int>`, position\: :ref:`Vector2i<class_Vector2i>`, pattern\: :ref:`TileMapPattern<class_TileMapPattern>`\ ) |
  149. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  150. | |void| | :ref:`update_internals<class_TileMap_method_update_internals>`\ (\ ) |
  151. +--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  152. .. rst-class:: classref-section-separator
  153. ----
  154. .. rst-class:: classref-descriptions-group
  155. Signals
  156. -------
  157. .. _class_TileMap_signal_changed:
  158. .. rst-class:: classref-signal
  159. **changed**\ (\ ) :ref:`๐Ÿ”—<class_TileMap_signal_changed>`
  160. Emitted when the :ref:`TileSet<class_TileSet>` of this TileMap changes.
  161. .. rst-class:: classref-section-separator
  162. ----
  163. .. rst-class:: classref-descriptions-group
  164. Enumerations
  165. ------------
  166. .. _enum_TileMap_VisibilityMode:
  167. .. rst-class:: classref-enumeration
  168. enum **VisibilityMode**: :ref:`๐Ÿ”—<enum_TileMap_VisibilityMode>`
  169. .. _class_TileMap_constant_VISIBILITY_MODE_DEFAULT:
  170. .. rst-class:: classref-enumeration-constant
  171. :ref:`VisibilityMode<enum_TileMap_VisibilityMode>` **VISIBILITY_MODE_DEFAULT** = ``0``
  172. Use the debug settings to determine visibility.
  173. .. _class_TileMap_constant_VISIBILITY_MODE_FORCE_HIDE:
  174. .. rst-class:: classref-enumeration-constant
  175. :ref:`VisibilityMode<enum_TileMap_VisibilityMode>` **VISIBILITY_MODE_FORCE_HIDE** = ``2``
  176. Always hide.
  177. .. _class_TileMap_constant_VISIBILITY_MODE_FORCE_SHOW:
  178. .. rst-class:: classref-enumeration-constant
  179. :ref:`VisibilityMode<enum_TileMap_VisibilityMode>` **VISIBILITY_MODE_FORCE_SHOW** = ``1``
  180. Always show.
  181. .. rst-class:: classref-section-separator
  182. ----
  183. .. rst-class:: classref-descriptions-group
  184. Property Descriptions
  185. ---------------------
  186. .. _class_TileMap_property_collision_animatable:
  187. .. rst-class:: classref-property
  188. :ref:`bool<class_bool>` **collision_animatable** = ``false`` :ref:`๐Ÿ”—<class_TileMap_property_collision_animatable>`
  189. .. rst-class:: classref-property-setget
  190. - |void| **set_collision_animatable**\ (\ value\: :ref:`bool<class_bool>`\ )
  191. - :ref:`bool<class_bool>` **is_collision_animatable**\ (\ )
  192. 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.
  193. \ **Note:** Enabling :ref:`collision_animatable<class_TileMap_property_collision_animatable>` may have a small performance impact, only do it if the TileMap is moving and has colliding tiles.
  194. .. rst-class:: classref-item-separator
  195. ----
  196. .. _class_TileMap_property_collision_visibility_mode:
  197. .. rst-class:: classref-property
  198. :ref:`VisibilityMode<enum_TileMap_VisibilityMode>` **collision_visibility_mode** = ``0`` :ref:`๐Ÿ”—<class_TileMap_property_collision_visibility_mode>`
  199. .. rst-class:: classref-property-setget
  200. - |void| **set_collision_visibility_mode**\ (\ value\: :ref:`VisibilityMode<enum_TileMap_VisibilityMode>`\ )
  201. - :ref:`VisibilityMode<enum_TileMap_VisibilityMode>` **get_collision_visibility_mode**\ (\ )
  202. Show or hide the TileMap's collision shapes. If set to :ref:`VISIBILITY_MODE_DEFAULT<class_TileMap_constant_VISIBILITY_MODE_DEFAULT>`, this depends on the show collision debug settings.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_TileMap_property_navigation_visibility_mode:
  206. .. rst-class:: classref-property
  207. :ref:`VisibilityMode<enum_TileMap_VisibilityMode>` **navigation_visibility_mode** = ``0`` :ref:`๐Ÿ”—<class_TileMap_property_navigation_visibility_mode>`
  208. .. rst-class:: classref-property-setget
  209. - |void| **set_navigation_visibility_mode**\ (\ value\: :ref:`VisibilityMode<enum_TileMap_VisibilityMode>`\ )
  210. - :ref:`VisibilityMode<enum_TileMap_VisibilityMode>` **get_navigation_visibility_mode**\ (\ )
  211. Show or hide the TileMap's navigation meshes. If set to :ref:`VISIBILITY_MODE_DEFAULT<class_TileMap_constant_VISIBILITY_MODE_DEFAULT>`, this depends on the show navigation debug settings.
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _class_TileMap_property_rendering_quadrant_size:
  215. .. rst-class:: classref-property
  216. :ref:`int<class_int>` **rendering_quadrant_size** = ``16`` :ref:`๐Ÿ”—<class_TileMap_property_rendering_quadrant_size>`
  217. .. rst-class:: classref-property-setget
  218. - |void| **set_rendering_quadrant_size**\ (\ value\: :ref:`int<class_int>`\ )
  219. - :ref:`int<class_int>` **get_rendering_quadrant_size**\ (\ )
  220. The TileMap's quadrant size. A quadrant is a group of tiles to be drawn together on a single canvas item, for optimization purposes. :ref:`rendering_quadrant_size<class_TileMap_property_rendering_quadrant_size>` 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.
  221. The quadrant size does not apply on Y-sorted layers, as tiles are grouped by Y position instead in that case.
  222. \ **Note:** As quadrants are created according to the map's coordinate system, the quadrant's "square shape" might not look like square in the TileMap's local coordinate system.
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_TileMap_property_tile_set:
  226. .. rst-class:: classref-property
  227. :ref:`TileSet<class_TileSet>` **tile_set** :ref:`๐Ÿ”—<class_TileMap_property_tile_set>`
  228. .. rst-class:: classref-property-setget
  229. - |void| **set_tileset**\ (\ value\: :ref:`TileSet<class_TileSet>`\ )
  230. - :ref:`TileSet<class_TileSet>` **get_tileset**\ (\ )
  231. The :ref:`TileSet<class_TileSet>` used by this **TileMap**. The textures, collisions, and additional behavior of all available tiles are stored here.
  232. .. rst-class:: classref-section-separator
  233. ----
  234. .. rst-class:: classref-descriptions-group
  235. Method Descriptions
  236. -------------------
  237. .. _class_TileMap_private_method__tile_data_runtime_update:
  238. .. rst-class:: classref-method
  239. |void| **_tile_data_runtime_update**\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, tile_data\: :ref:`TileData<class_TileData>`\ ) |virtual| :ref:`๐Ÿ”—<class_TileMap_private_method__tile_data_runtime_update>`
  240. Called with a TileData object about to be used internally by the TileMap, allowing its modification at runtime.
  241. This method is only called if :ref:`_use_tile_data_runtime_update<class_TileMap_private_method__use_tile_data_runtime_update>` is implemented and returns ``true`` for the given tile ``coords`` and ``layer``.
  242. \ **Warning:** The ``tile_data`` object's sub-resources are the same as the one in the TileSet. Modifying them might impact the whole TileSet. Instead, make sure to duplicate those resources.
  243. \ **Note:** If the properties of ``tile_data`` object should change over time, use :ref:`notify_runtime_tile_data_update<class_TileMap_method_notify_runtime_tile_data_update>` to notify the TileMap it needs an update.
  244. .. rst-class:: classref-item-separator
  245. ----
  246. .. _class_TileMap_private_method__use_tile_data_runtime_update:
  247. .. rst-class:: classref-method
  248. :ref:`bool<class_bool>` **_use_tile_data_runtime_update**\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`\ ) |virtual| :ref:`๐Ÿ”—<class_TileMap_private_method__use_tile_data_runtime_update>`
  249. Should return ``true`` if the tile at coordinates ``coords`` on layer ``layer`` requires a runtime update.
  250. \ **Warning:** Make sure this function only return ``true`` when needed. Any tile processed at runtime without a need for it will imply a significant performance penalty.
  251. \ **Note:** If the result of this function should changed, use :ref:`notify_runtime_tile_data_update<class_TileMap_method_notify_runtime_tile_data_update>` to notify the TileMap it needs an update.
  252. .. rst-class:: classref-item-separator
  253. ----
  254. .. _class_TileMap_method_add_layer:
  255. .. rst-class:: classref-method
  256. |void| **add_layer**\ (\ to_position\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_add_layer>`
  257. Adds a layer at the given position ``to_position`` in the array. If ``to_position`` is negative, the position is counted from the end, with ``-1`` adding the layer at the end of the array.
  258. .. rst-class:: classref-item-separator
  259. ----
  260. .. _class_TileMap_method_clear:
  261. .. rst-class:: classref-method
  262. |void| **clear**\ (\ ) :ref:`๐Ÿ”—<class_TileMap_method_clear>`
  263. Clears all cells.
  264. .. rst-class:: classref-item-separator
  265. ----
  266. .. _class_TileMap_method_clear_layer:
  267. .. rst-class:: classref-method
  268. |void| **clear_layer**\ (\ layer\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_clear_layer>`
  269. Clears all cells on the given layer.
  270. If ``layer`` is negative, the layers are accessed from the last one.
  271. .. rst-class:: classref-item-separator
  272. ----
  273. .. _class_TileMap_method_erase_cell:
  274. .. rst-class:: classref-method
  275. |void| **erase_cell**\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_erase_cell>`
  276. Erases the cell on layer ``layer`` at coordinates ``coords``.
  277. If ``layer`` is negative, the layers are accessed from the last one.
  278. .. rst-class:: classref-item-separator
  279. ----
  280. .. _class_TileMap_method_fix_invalid_tiles:
  281. .. rst-class:: classref-method
  282. |void| **fix_invalid_tiles**\ (\ ) :ref:`๐Ÿ”—<class_TileMap_method_fix_invalid_tiles>`
  283. Clears cells that do not exist in the tileset.
  284. .. rst-class:: classref-item-separator
  285. ----
  286. .. _class_TileMap_method_force_update:
  287. .. rst-class:: classref-method
  288. |void| **force_update**\ (\ layer\: :ref:`int<class_int>` = -1\ ) :ref:`๐Ÿ”—<class_TileMap_method_force_update>`
  289. **Deprecated:** Use :ref:`notify_runtime_tile_data_update<class_TileMap_method_notify_runtime_tile_data_update>` and/or :ref:`update_internals<class_TileMap_method_update_internals>` instead.
  290. Forces the TileMap and the layer ``layer`` to update.
  291. .. rst-class:: classref-item-separator
  292. ----
  293. .. _class_TileMap_method_get_cell_alternative_tile:
  294. .. rst-class:: classref-method
  295. :ref:`int<class_int>` **get_cell_alternative_tile**\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, use_proxies\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_cell_alternative_tile>`
  296. Returns the tile alternative ID of the cell on layer ``layer`` at ``coords``.
  297. If ``use_proxies`` is ``false``, ignores the :ref:`TileSet<class_TileSet>`'s tile proxies, returning the raw alternative identifier. See :ref:`TileSet.map_tile_proxy<class_TileSet_method_map_tile_proxy>`.
  298. If ``layer`` is negative, the layers are accessed from the last one.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_TileMap_method_get_cell_atlas_coords:
  302. .. rst-class:: classref-method
  303. :ref:`Vector2i<class_Vector2i>` **get_cell_atlas_coords**\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, use_proxies\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_cell_atlas_coords>`
  304. Returns the tile atlas coordinates ID of the cell on layer ``layer`` at coordinates ``coords``. Returns ``Vector2i(-1, -1)`` if the cell does not exist.
  305. If ``use_proxies`` is ``false``, ignores the :ref:`TileSet<class_TileSet>`'s tile proxies, returning the raw atlas coordinate identifier. See :ref:`TileSet.map_tile_proxy<class_TileSet_method_map_tile_proxy>`.
  306. If ``layer`` is negative, the layers are accessed from the last one.
  307. .. rst-class:: classref-item-separator
  308. ----
  309. .. _class_TileMap_method_get_cell_source_id:
  310. .. rst-class:: classref-method
  311. :ref:`int<class_int>` **get_cell_source_id**\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, use_proxies\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_cell_source_id>`
  312. Returns the tile source ID of the cell on layer ``layer`` at coordinates ``coords``. Returns ``-1`` if the cell does not exist.
  313. If ``use_proxies`` is ``false``, ignores the :ref:`TileSet<class_TileSet>`'s tile proxies, returning the raw source identifier. See :ref:`TileSet.map_tile_proxy<class_TileSet_method_map_tile_proxy>`.
  314. If ``layer`` is negative, the layers are accessed from the last one.
  315. .. rst-class:: classref-item-separator
  316. ----
  317. .. _class_TileMap_method_get_cell_tile_data:
  318. .. rst-class:: classref-method
  319. :ref:`TileData<class_TileData>` **get_cell_tile_data**\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, use_proxies\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_cell_tile_data>`
  320. Returns the :ref:`TileData<class_TileData>` object associated with the given cell, or ``null`` if the cell does not exist or is not a :ref:`TileSetAtlasSource<class_TileSetAtlasSource>`.
  321. If ``layer`` is negative, the layers are accessed from the last one.
  322. ::
  323. func get_clicked_tile_power():
  324. var clicked_cell = tile_map.local_to_map(tile_map.get_local_mouse_position())
  325. var data = tile_map.get_cell_tile_data(0, clicked_cell)
  326. if data:
  327. return data.get_custom_data("power")
  328. else:
  329. return 0
  330. If ``use_proxies`` is ``false``, ignores the :ref:`TileSet<class_TileSet>`'s tile proxies. See :ref:`TileSet.map_tile_proxy<class_TileSet_method_map_tile_proxy>`.
  331. .. rst-class:: classref-item-separator
  332. ----
  333. .. _class_TileMap_method_get_coords_for_body_rid:
  334. .. rst-class:: classref-method
  335. :ref:`Vector2i<class_Vector2i>` **get_coords_for_body_rid**\ (\ body\: :ref:`RID<class_RID>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_get_coords_for_body_rid>`
  336. Returns the coordinates of the tile for given physics body RID. Such RID can be retrieved from :ref:`KinematicCollision2D.get_collider_rid<class_KinematicCollision2D_method_get_collider_rid>`, when colliding with a tile.
  337. .. rst-class:: classref-item-separator
  338. ----
  339. .. _class_TileMap_method_get_layer_for_body_rid:
  340. .. rst-class:: classref-method
  341. :ref:`int<class_int>` **get_layer_for_body_rid**\ (\ body\: :ref:`RID<class_RID>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_get_layer_for_body_rid>`
  342. Returns the tilemap layer of the tile for given physics body RID. Such RID can be retrieved from :ref:`KinematicCollision2D.get_collider_rid<class_KinematicCollision2D_method_get_collider_rid>`, when colliding with a tile.
  343. .. rst-class:: classref-item-separator
  344. ----
  345. .. _class_TileMap_method_get_layer_modulate:
  346. .. rst-class:: classref-method
  347. :ref:`Color<class_Color>` **get_layer_modulate**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_layer_modulate>`
  348. Returns a TileMap layer's modulate.
  349. If ``layer`` is negative, the layers are accessed from the last one.
  350. .. rst-class:: classref-item-separator
  351. ----
  352. .. _class_TileMap_method_get_layer_name:
  353. .. rst-class:: classref-method
  354. :ref:`String<class_String>` **get_layer_name**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_layer_name>`
  355. Returns a TileMap layer's name.
  356. If ``layer`` is negative, the layers are accessed from the last one.
  357. .. rst-class:: classref-item-separator
  358. ----
  359. .. _class_TileMap_method_get_layer_navigation_map:
  360. .. rst-class:: classref-method
  361. :ref:`RID<class_RID>` **get_layer_navigation_map**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_layer_navigation_map>`
  362. Returns the :ref:`RID<class_RID>` of the :ref:`NavigationServer2D<class_NavigationServer2D>` navigation map assigned to the specified TileMap layer ``layer``.
  363. By default the TileMap uses the default :ref:`World2D<class_World2D>` navigation map for the first TileMap layer. For each additional TileMap layer a new navigation map is created for the additional layer.
  364. In order to make :ref:`NavigationAgent2D<class_NavigationAgent2D>` switch between TileMap layer navigation maps use :ref:`NavigationAgent2D.set_navigation_map<class_NavigationAgent2D_method_set_navigation_map>` with the navigation map received from :ref:`get_layer_navigation_map<class_TileMap_method_get_layer_navigation_map>`.
  365. If ``layer`` is negative, the layers are accessed from the last one.
  366. .. rst-class:: classref-item-separator
  367. ----
  368. .. _class_TileMap_method_get_layer_y_sort_origin:
  369. .. rst-class:: classref-method
  370. :ref:`int<class_int>` **get_layer_y_sort_origin**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_layer_y_sort_origin>`
  371. Returns a TileMap layer's Y sort origin.
  372. If ``layer`` is negative, the layers are accessed from the last one.
  373. .. rst-class:: classref-item-separator
  374. ----
  375. .. _class_TileMap_method_get_layer_z_index:
  376. .. rst-class:: classref-method
  377. :ref:`int<class_int>` **get_layer_z_index**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_layer_z_index>`
  378. Returns a TileMap layer's Z-index value.
  379. If ``layer`` is negative, the layers are accessed from the last one.
  380. .. rst-class:: classref-item-separator
  381. ----
  382. .. _class_TileMap_method_get_layers_count:
  383. .. rst-class:: classref-method
  384. :ref:`int<class_int>` **get_layers_count**\ (\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_layers_count>`
  385. Returns the number of layers in the TileMap.
  386. .. rst-class:: classref-item-separator
  387. ----
  388. .. _class_TileMap_method_get_navigation_map:
  389. .. rst-class:: classref-method
  390. :ref:`RID<class_RID>` **get_navigation_map**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_navigation_map>`
  391. **Deprecated:** Use :ref:`get_layer_navigation_map<class_TileMap_method_get_layer_navigation_map>` instead.
  392. Returns the :ref:`RID<class_RID>` of the :ref:`NavigationServer2D<class_NavigationServer2D>` navigation map assigned to the specified TileMap layer ``layer``.
  393. .. rst-class:: classref-item-separator
  394. ----
  395. .. _class_TileMap_method_get_neighbor_cell:
  396. .. rst-class:: classref-method
  397. :ref:`Vector2i<class_Vector2i>` **get_neighbor_cell**\ (\ coords\: :ref:`Vector2i<class_Vector2i>`, neighbor\: :ref:`CellNeighbor<enum_TileSet_CellNeighbor>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_neighbor_cell>`
  398. 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.
  399. .. rst-class:: classref-item-separator
  400. ----
  401. .. _class_TileMap_method_get_pattern:
  402. .. rst-class:: classref-method
  403. :ref:`TileMapPattern<class_TileMapPattern>` **get_pattern**\ (\ layer\: :ref:`int<class_int>`, coords_array\: :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\]\ ) :ref:`๐Ÿ”—<class_TileMap_method_get_pattern>`
  404. Creates a new :ref:`TileMapPattern<class_TileMapPattern>` from the given layer and set of cells.
  405. If ``layer`` is negative, the layers are accessed from the last one.
  406. .. rst-class:: classref-item-separator
  407. ----
  408. .. _class_TileMap_method_get_surrounding_cells:
  409. .. rst-class:: classref-method
  410. :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\] **get_surrounding_cells**\ (\ coords\: :ref:`Vector2i<class_Vector2i>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_get_surrounding_cells>`
  411. Returns the list of all neighbourings cells to the one at ``coords``.
  412. .. rst-class:: classref-item-separator
  413. ----
  414. .. _class_TileMap_method_get_used_cells:
  415. .. rst-class:: classref-method
  416. :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\] **get_used_cells**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_used_cells>`
  417. Returns a :ref:`Vector2i<class_Vector2i>` 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.
  418. If ``layer`` is negative, the layers are accessed from the last one.
  419. .. rst-class:: classref-item-separator
  420. ----
  421. .. _class_TileMap_method_get_used_cells_by_id:
  422. .. rst-class:: classref-method
  423. :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\] **get_used_cells_by_id**\ (\ layer\: :ref:`int<class_int>`, source_id\: :ref:`int<class_int>` = -1, atlas_coords\: :ref:`Vector2i<class_Vector2i>` = Vector2i(-1, -1), alternative_tile\: :ref:`int<class_int>` = -1\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_used_cells_by_id>`
  424. Returns a :ref:`Vector2i<class_Vector2i>` array with the positions of all cells containing a tile in the given layer. Tiles may be filtered according to their source (``source_id``), their atlas coordinates (``atlas_coords``) or alternative id (``alternative_tile``).
  425. If a parameter has its value set to the default one, this parameter is not used to filter a cell. Thus, if all parameters have their respective default value, this method returns the same result as :ref:`get_used_cells<class_TileMap_method_get_used_cells>`.
  426. 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.
  427. If ``layer`` is negative, the layers are accessed from the last one.
  428. .. rst-class:: classref-item-separator
  429. ----
  430. .. _class_TileMap_method_get_used_rect:
  431. .. rst-class:: classref-method
  432. :ref:`Rect2i<class_Rect2i>` **get_used_rect**\ (\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_get_used_rect>`
  433. Returns a rectangle enclosing the used (non-empty) tiles of the map, including all layers.
  434. .. rst-class:: classref-item-separator
  435. ----
  436. .. _class_TileMap_method_is_layer_enabled:
  437. .. rst-class:: classref-method
  438. :ref:`bool<class_bool>` **is_layer_enabled**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_is_layer_enabled>`
  439. Returns if a layer is enabled.
  440. If ``layer`` is negative, the layers are accessed from the last one.
  441. .. rst-class:: classref-item-separator
  442. ----
  443. .. _class_TileMap_method_is_layer_navigation_enabled:
  444. .. rst-class:: classref-method
  445. :ref:`bool<class_bool>` **is_layer_navigation_enabled**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_is_layer_navigation_enabled>`
  446. Returns if a layer's built-in navigation regions generation is enabled.
  447. .. rst-class:: classref-item-separator
  448. ----
  449. .. _class_TileMap_method_is_layer_y_sort_enabled:
  450. .. rst-class:: classref-method
  451. :ref:`bool<class_bool>` **is_layer_y_sort_enabled**\ (\ layer\: :ref:`int<class_int>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_is_layer_y_sort_enabled>`
  452. Returns if a layer Y-sorts its tiles.
  453. If ``layer`` is negative, the layers are accessed from the last one.
  454. .. rst-class:: classref-item-separator
  455. ----
  456. .. _class_TileMap_method_local_to_map:
  457. .. rst-class:: classref-method
  458. :ref:`Vector2i<class_Vector2i>` **local_to_map**\ (\ local_position\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_local_to_map>`
  459. Returns the map coordinates of the cell containing the given ``local_position``. If ``local_position`` is in global coordinates, consider using :ref:`Node2D.to_local<class_Node2D_method_to_local>` before passing it to this method. See also :ref:`map_to_local<class_TileMap_method_map_to_local>`.
  460. .. rst-class:: classref-item-separator
  461. ----
  462. .. _class_TileMap_method_map_pattern:
  463. .. rst-class:: classref-method
  464. :ref:`Vector2i<class_Vector2i>` **map_pattern**\ (\ position_in_tilemap\: :ref:`Vector2i<class_Vector2i>`, coords_in_pattern\: :ref:`Vector2i<class_Vector2i>`, pattern\: :ref:`TileMapPattern<class_TileMapPattern>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_map_pattern>`
  465. Returns for the given coordinate ``coords_in_pattern`` in a :ref:`TileMapPattern<class_TileMapPattern>` the corresponding cell coordinates if the pattern was pasted at the ``position_in_tilemap`` coordinates (see :ref:`set_pattern<class_TileMap_method_set_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``.
  466. .. rst-class:: classref-item-separator
  467. ----
  468. .. _class_TileMap_method_map_to_local:
  469. .. rst-class:: classref-method
  470. :ref:`Vector2<class_Vector2>` **map_to_local**\ (\ map_position\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`๐Ÿ”—<class_TileMap_method_map_to_local>`
  471. Returns the centered position of a cell in the TileMap's local coordinate space. To convert the returned value into global coordinates, use :ref:`Node2D.to_global<class_Node2D_method_to_global>`. See also :ref:`local_to_map<class_TileMap_method_local_to_map>`.
  472. \ **Note:** This may not correspond to the visual position of the tile, i.e. it ignores the :ref:`TileData.texture_origin<class_TileData_property_texture_origin>` property of individual tiles.
  473. .. rst-class:: classref-item-separator
  474. ----
  475. .. _class_TileMap_method_move_layer:
  476. .. rst-class:: classref-method
  477. |void| **move_layer**\ (\ layer\: :ref:`int<class_int>`, to_position\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_move_layer>`
  478. Moves the layer at index ``layer`` to the given position ``to_position`` in the array.
  479. .. rst-class:: classref-item-separator
  480. ----
  481. .. _class_TileMap_method_notify_runtime_tile_data_update:
  482. .. rst-class:: classref-method
  483. |void| **notify_runtime_tile_data_update**\ (\ layer\: :ref:`int<class_int>` = -1\ ) :ref:`๐Ÿ”—<class_TileMap_method_notify_runtime_tile_data_update>`
  484. Notifies the TileMap node that calls to :ref:`_use_tile_data_runtime_update<class_TileMap_private_method__use_tile_data_runtime_update>` or :ref:`_tile_data_runtime_update<class_TileMap_private_method__tile_data_runtime_update>` will lead to different results. This will thus trigger a TileMap update.
  485. If ``layer`` is provided, only notifies changes for the given layer. Providing the ``layer`` argument (when applicable) is usually preferred for performance reasons.
  486. \ **Warning:** Updating the TileMap is computationally expensive and may impact performance. Try to limit the number of calls to this function to avoid unnecessary update.
  487. \ **Note:** This does not trigger a direct update of the TileMap, the update will be done at the end of the frame as usual (unless you call :ref:`update_internals<class_TileMap_method_update_internals>`).
  488. .. rst-class:: classref-item-separator
  489. ----
  490. .. _class_TileMap_method_remove_layer:
  491. .. rst-class:: classref-method
  492. |void| **remove_layer**\ (\ layer\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_remove_layer>`
  493. Removes the layer at index ``layer``.
  494. .. rst-class:: classref-item-separator
  495. ----
  496. .. _class_TileMap_method_set_cell:
  497. .. rst-class:: classref-method
  498. |void| **set_cell**\ (\ layer\: :ref:`int<class_int>`, coords\: :ref:`Vector2i<class_Vector2i>`, source_id\: :ref:`int<class_int>` = -1, atlas_coords\: :ref:`Vector2i<class_Vector2i>` = Vector2i(-1, -1), alternative_tile\: :ref:`int<class_int>` = 0\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_cell>`
  499. Sets the tile identifiers for the cell on layer ``layer`` at coordinates ``coords``. Each tile of the :ref:`TileSet<class_TileSet>` is identified using three parts:
  500. - The source identifier ``source_id`` identifies a :ref:`TileSetSource<class_TileSetSource>` identifier. See :ref:`TileSet.set_source_id<class_TileSet_method_set_source_id>`,
  501. - The atlas coordinates identifier ``atlas_coords`` identifies a tile coordinates in the atlas (if the source is a :ref:`TileSetAtlasSource<class_TileSetAtlasSource>`). For :ref:`TileSetScenesCollectionSource<class_TileSetScenesCollectionSource>` it should always be ``Vector2i(0, 0)``),
  502. - The alternative tile identifier ``alternative_tile`` identifies a tile alternative in the atlas (if the source is a :ref:`TileSetAtlasSource<class_TileSetAtlasSource>`), and the scene for a :ref:`TileSetScenesCollectionSource<class_TileSetScenesCollectionSource>`.
  503. If ``source_id`` is set to ``-1``, ``atlas_coords`` to ``Vector2i(-1, -1)`` or ``alternative_tile`` to ``-1``, the cell will be erased. An erased cell gets **all** its identifiers automatically set to their respective invalid values, namely ``-1``, ``Vector2i(-1, -1)`` and ``-1``.
  504. If ``layer`` is negative, the layers are accessed from the last one.
  505. .. rst-class:: classref-item-separator
  506. ----
  507. .. _class_TileMap_method_set_cells_terrain_connect:
  508. .. rst-class:: classref-method
  509. |void| **set_cells_terrain_connect**\ (\ layer\: :ref:`int<class_int>`, cells\: :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\], terrain_set\: :ref:`int<class_int>`, terrain\: :ref:`int<class_int>`, ignore_empty_terrains\: :ref:`bool<class_bool>` = true\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_cells_terrain_connect>`
  510. Update all the cells in the ``cells`` coordinates array so that they use the given ``terrain`` for the given ``terrain_set``. 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.
  511. If ``ignore_empty_terrains`` is true, empty terrains will be ignored when trying to find the best fitting tile for the given terrain constraints.
  512. If ``layer`` is negative, the layers are accessed from the last one.
  513. \ **Note:** To work correctly, this method requires the TileMap's TileSet to have terrains set up with all required terrain combinations. Otherwise, it may produce unexpected results.
  514. .. rst-class:: classref-item-separator
  515. ----
  516. .. _class_TileMap_method_set_cells_terrain_path:
  517. .. rst-class:: classref-method
  518. |void| **set_cells_terrain_path**\ (\ layer\: :ref:`int<class_int>`, path\: :ref:`Array<class_Array>`\[:ref:`Vector2i<class_Vector2i>`\], terrain_set\: :ref:`int<class_int>`, terrain\: :ref:`int<class_int>`, ignore_empty_terrains\: :ref:`bool<class_bool>` = true\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_cells_terrain_path>`
  519. Update all the cells in the ``path`` coordinates array so that they use the given ``terrain`` for the given ``terrain_set``. 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.
  520. If ``ignore_empty_terrains`` is true, empty terrains will be ignored when trying to find the best fitting tile for the given terrain constraints.
  521. If ``layer`` is negative, the layers are accessed from the last one.
  522. \ **Note:** To work correctly, this method requires the TileMap's TileSet to have terrains set up with all required terrain combinations. Otherwise, it may produce unexpected results.
  523. .. rst-class:: classref-item-separator
  524. ----
  525. .. _class_TileMap_method_set_layer_enabled:
  526. .. rst-class:: classref-method
  527. |void| **set_layer_enabled**\ (\ layer\: :ref:`int<class_int>`, enabled\: :ref:`bool<class_bool>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_layer_enabled>`
  528. Enables or disables the layer ``layer``. A disabled layer is not processed at all (no rendering, no physics, etc.).
  529. If ``layer`` is negative, the layers are accessed from the last one.
  530. .. rst-class:: classref-item-separator
  531. ----
  532. .. _class_TileMap_method_set_layer_modulate:
  533. .. rst-class:: classref-method
  534. |void| **set_layer_modulate**\ (\ layer\: :ref:`int<class_int>`, modulate\: :ref:`Color<class_Color>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_layer_modulate>`
  535. Sets a layer's color. It will be multiplied by tile's color and TileMap's modulate.
  536. If ``layer`` is negative, the layers are accessed from the last one.
  537. .. rst-class:: classref-item-separator
  538. ----
  539. .. _class_TileMap_method_set_layer_name:
  540. .. rst-class:: classref-method
  541. |void| **set_layer_name**\ (\ layer\: :ref:`int<class_int>`, name\: :ref:`String<class_String>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_layer_name>`
  542. Sets a layer's name. This is mostly useful in the editor.
  543. If ``layer`` is negative, the layers are accessed from the last one.
  544. .. rst-class:: classref-item-separator
  545. ----
  546. .. _class_TileMap_method_set_layer_navigation_enabled:
  547. .. rst-class:: classref-method
  548. |void| **set_layer_navigation_enabled**\ (\ layer\: :ref:`int<class_int>`, enabled\: :ref:`bool<class_bool>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_layer_navigation_enabled>`
  549. Enables or disables a layer's built-in navigation regions generation. Disable this if you need to bake navigation regions from a TileMap using a :ref:`NavigationRegion2D<class_NavigationRegion2D>` node.
  550. .. rst-class:: classref-item-separator
  551. ----
  552. .. _class_TileMap_method_set_layer_navigation_map:
  553. .. rst-class:: classref-method
  554. |void| **set_layer_navigation_map**\ (\ layer\: :ref:`int<class_int>`, map\: :ref:`RID<class_RID>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_layer_navigation_map>`
  555. Assigns ``map`` as a :ref:`NavigationServer2D<class_NavigationServer2D>` navigation map for the specified TileMap layer ``layer``.
  556. By default the TileMap uses the default :ref:`World2D<class_World2D>` navigation map for the first TileMap layer. For each additional TileMap layer a new navigation map is created for the additional layer.
  557. In order to make :ref:`NavigationAgent2D<class_NavigationAgent2D>` switch between TileMap layer navigation maps use :ref:`NavigationAgent2D.set_navigation_map<class_NavigationAgent2D_method_set_navigation_map>` with the navigation map received from :ref:`get_layer_navigation_map<class_TileMap_method_get_layer_navigation_map>`.
  558. If ``layer`` is negative, the layers are accessed from the last one.
  559. .. rst-class:: classref-item-separator
  560. ----
  561. .. _class_TileMap_method_set_layer_y_sort_enabled:
  562. .. rst-class:: classref-method
  563. |void| **set_layer_y_sort_enabled**\ (\ layer\: :ref:`int<class_int>`, y_sort_enabled\: :ref:`bool<class_bool>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_layer_y_sort_enabled>`
  564. 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.
  565. 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 behavior.
  566. If ``layer`` is negative, the layers are accessed from the last one.
  567. .. rst-class:: classref-item-separator
  568. ----
  569. .. _class_TileMap_method_set_layer_y_sort_origin:
  570. .. rst-class:: classref-method
  571. |void| **set_layer_y_sort_origin**\ (\ layer\: :ref:`int<class_int>`, y_sort_origin\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_layer_y_sort_origin>`
  572. Sets a layer's Y-sort origin value. This Y-sort origin value is added to each tile's Y-sort origin value.
  573. This allows, for example, to fake a different height level on each layer. This can be useful for top-down view games.
  574. If ``layer`` is negative, the layers are accessed from the last one.
  575. .. rst-class:: classref-item-separator
  576. ----
  577. .. _class_TileMap_method_set_layer_z_index:
  578. .. rst-class:: classref-method
  579. |void| **set_layer_z_index**\ (\ layer\: :ref:`int<class_int>`, z_index\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_layer_z_index>`
  580. Sets a layers Z-index value. This Z-index is added to each tile's Z-index value.
  581. If ``layer`` is negative, the layers are accessed from the last one.
  582. .. rst-class:: classref-item-separator
  583. ----
  584. .. _class_TileMap_method_set_navigation_map:
  585. .. rst-class:: classref-method
  586. |void| **set_navigation_map**\ (\ layer\: :ref:`int<class_int>`, map\: :ref:`RID<class_RID>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_navigation_map>`
  587. **Deprecated:** Use :ref:`set_layer_navigation_map<class_TileMap_method_set_layer_navigation_map>` instead.
  588. Assigns ``map`` as a :ref:`NavigationServer2D<class_NavigationServer2D>` navigation map for the specified TileMap layer ``layer``.
  589. .. rst-class:: classref-item-separator
  590. ----
  591. .. _class_TileMap_method_set_pattern:
  592. .. rst-class:: classref-method
  593. |void| **set_pattern**\ (\ layer\: :ref:`int<class_int>`, position\: :ref:`Vector2i<class_Vector2i>`, pattern\: :ref:`TileMapPattern<class_TileMapPattern>`\ ) :ref:`๐Ÿ”—<class_TileMap_method_set_pattern>`
  594. Paste the given :ref:`TileMapPattern<class_TileMapPattern>` at the given ``position`` and ``layer`` in the tile map.
  595. If ``layer`` is negative, the layers are accessed from the last one.
  596. .. rst-class:: classref-item-separator
  597. ----
  598. .. _class_TileMap_method_update_internals:
  599. .. rst-class:: classref-method
  600. |void| **update_internals**\ (\ ) :ref:`๐Ÿ”—<class_TileMap_method_update_internals>`
  601. Triggers a direct update of the TileMap. Usually, calling this function is not needed, as TileMap node updates automatically when one of its properties or cells is modified.
  602. However, for performance reasons, those updates are batched and delayed to the end of the frame. Calling this function will force the TileMap to update right away instead.
  603. \ **Warning:** Updating the TileMap is computationally expensive and may impact performance. Try to limit the number of updates and how many tiles they impact.
  604. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  605. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  606. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  607. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  608. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  609. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  610. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  611. .. |void| replace:: :abbr:`void (No return value.)`