class_tilemap.rst 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/TileMap.xml.
  6. .. _class_TileMap:
  7. TileMap
  8. =======
  9. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. Node for 2D tile-based maps.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Node for 2D tile-based maps. Tilemaps use a :ref:`TileSet<class_TileSet>` which contain a list of tiles (textures plus optional collision, navigation, and/or occluder shapes) which are used to create grid-based maps.
  15. When doing physics queries against the tilemap, the cell coordinates are encoded as ``metadata`` for each detected collision shape returned by methods such as :ref:`Physics2DDirectSpaceState.intersect_shape<class_Physics2DDirectSpaceState_method_intersect_shape>`, :ref:`Physics2DDirectBodyState.get_contact_collider_shape_metadata<class_Physics2DDirectBodyState_method_get_contact_collider_shape_metadata>`, etc.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Using Tilemaps <../tutorials/2d/using_tilemaps>`
  20. - `2D Platformer Demo <https://godotengine.org/asset-library/asset/120>`__
  21. - `2D Isometric Demo <https://godotengine.org/asset-library/asset/112>`__
  22. - `2D Hexagonal Demo <https://godotengine.org/asset-library/asset/111>`__
  23. - `2D Navigation Astar Demo <https://godotengine.org/asset-library/asset/519>`__
  24. - `2D Role Playing Game Demo <https://godotengine.org/asset-library/asset/520>`__
  25. - `2D Kinematic Character Demo <https://godotengine.org/asset-library/asset/113>`__
  26. .. rst-class:: classref-reftable-group
  27. Properties
  28. ----------
  29. .. table::
  30. :widths: auto
  31. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  32. | :ref:`bool<class_bool>` | :ref:`bake_navigation<class_TileMap_property_bake_navigation>` | ``false`` |
  33. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`cell_clip_uv<class_TileMap_property_cell_clip_uv>` | ``false`` |
  35. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  36. | :ref:`Transform2D<class_Transform2D>` | :ref:`cell_custom_transform<class_TileMap_property_cell_custom_transform>` | ``Transform2D( 64, 0, 0, 64, 0, 0 )`` |
  37. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  38. | :ref:`HalfOffset<enum_TileMap_HalfOffset>` | :ref:`cell_half_offset<class_TileMap_property_cell_half_offset>` | ``2`` |
  39. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`cell_quadrant_size<class_TileMap_property_cell_quadrant_size>` | ``16`` |
  41. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  42. | :ref:`Vector2<class_Vector2>` | :ref:`cell_size<class_TileMap_property_cell_size>` | ``Vector2( 64, 64 )`` |
  43. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  44. | :ref:`TileOrigin<enum_TileMap_TileOrigin>` | :ref:`cell_tile_origin<class_TileMap_property_cell_tile_origin>` | ``0`` |
  45. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`cell_y_sort<class_TileMap_property_cell_y_sort>` | ``false`` |
  47. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`centered_textures<class_TileMap_property_centered_textures>` | ``false`` |
  49. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  50. | :ref:`float<class_float>` | :ref:`collision_bounce<class_TileMap_property_collision_bounce>` | ``0.0`` |
  51. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  52. | :ref:`float<class_float>` | :ref:`collision_friction<class_TileMap_property_collision_friction>` | ``1.0`` |
  53. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  54. | :ref:`int<class_int>` | :ref:`collision_layer<class_TileMap_property_collision_layer>` | ``1`` |
  55. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  56. | :ref:`int<class_int>` | :ref:`collision_mask<class_TileMap_property_collision_mask>` | ``1`` |
  57. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`collision_use_kinematic<class_TileMap_property_collision_use_kinematic>` | ``false`` |
  59. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  60. | :ref:`bool<class_bool>` | :ref:`collision_use_parent<class_TileMap_property_collision_use_parent>` | ``false`` |
  61. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  62. | :ref:`bool<class_bool>` | :ref:`compatibility_mode<class_TileMap_property_compatibility_mode>` | ``false`` |
  63. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  64. | :ref:`Mode<enum_TileMap_Mode>` | :ref:`mode<class_TileMap_property_mode>` | ``0`` |
  65. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  66. | :ref:`int<class_int>` | :ref:`navigation_layers<class_TileMap_property_navigation_layers>` | ``1`` |
  67. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  68. | :ref:`int<class_int>` | :ref:`occluder_light_mask<class_TileMap_property_occluder_light_mask>` | ``1`` |
  69. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  70. | :ref:`bool<class_bool>` | :ref:`show_collision<class_TileMap_property_show_collision>` | ``false`` |
  71. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  72. | :ref:`TileSet<class_TileSet>` | :ref:`tile_set<class_TileMap_property_tile_set>` | |
  73. +--------------------------------------------+--------------------------------------------------------------------------------+---------------------------------------+
  74. .. rst-class:: classref-reftable-group
  75. Methods
  76. -------
  77. .. table::
  78. :widths: auto
  79. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`clear<class_TileMap_method_clear>` **(** **)** |
  81. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`fix_invalid_tiles<class_TileMap_method_fix_invalid_tiles>` **(** **)** |
  83. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`int<class_int>` | :ref:`get_cell<class_TileMap_method_get_cell>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const| |
  85. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`Vector2<class_Vector2>` | :ref:`get_cell_autotile_coord<class_TileMap_method_get_cell_autotile_coord>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const| |
  87. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`int<class_int>` | :ref:`get_cellv<class_TileMap_method_get_cellv>` **(** :ref:`Vector2<class_Vector2>` position **)** |const| |
  89. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`bool<class_bool>` | :ref:`get_collision_layer_bit<class_TileMap_method_get_collision_layer_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  91. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`bool<class_bool>` | :ref:`get_collision_mask_bit<class_TileMap_method_get_collision_mask_bit>` **(** :ref:`int<class_int>` bit **)** |const| |
  93. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`Array<class_Array>` | :ref:`get_used_cells<class_TileMap_method_get_used_cells>` **(** **)** |const| |
  95. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`Array<class_Array>` | :ref:`get_used_cells_by_id<class_TileMap_method_get_used_cells_by_id>` **(** :ref:`int<class_int>` id **)** |const| |
  97. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Rect2<class_Rect2>` | :ref:`get_used_rect<class_TileMap_method_get_used_rect>` **(** **)** |
  99. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`bool<class_bool>` | :ref:`is_cell_transposed<class_TileMap_method_is_cell_transposed>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const| |
  101. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`bool<class_bool>` | :ref:`is_cell_x_flipped<class_TileMap_method_is_cell_x_flipped>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const| |
  103. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`bool<class_bool>` | :ref:`is_cell_y_flipped<class_TileMap_method_is_cell_y_flipped>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const| |
  105. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`Vector2<class_Vector2>` | :ref:`map_to_world<class_TileMap_method_map_to_world>` **(** :ref:`Vector2<class_Vector2>` map_position, :ref:`bool<class_bool>` ignore_half_ofs=false **)** |const| |
  107. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | void | :ref:`set_cell<class_TileMap_method_set_cell>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` tile, :ref:`bool<class_bool>` flip_x=false, :ref:`bool<class_bool>` flip_y=false, :ref:`bool<class_bool>` transpose=false, :ref:`Vector2<class_Vector2>` autotile_coord=Vector2( 0, 0 ) **)** |
  109. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | void | :ref:`set_cellv<class_TileMap_method_set_cellv>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` tile, :ref:`bool<class_bool>` flip_x=false, :ref:`bool<class_bool>` flip_y=false, :ref:`bool<class_bool>` transpose=false, :ref:`Vector2<class_Vector2>` autotile_coord=Vector2( 0, 0 ) **)** |
  111. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | void | :ref:`set_collision_layer_bit<class_TileMap_method_set_collision_layer_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  113. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | void | :ref:`set_collision_mask_bit<class_TileMap_method_set_collision_mask_bit>` **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)** |
  115. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | void | :ref:`update_bitmask_area<class_TileMap_method_update_bitmask_area>` **(** :ref:`Vector2<class_Vector2>` position **)** |
  117. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | void | :ref:`update_bitmask_region<class_TileMap_method_update_bitmask_region>` **(** :ref:`Vector2<class_Vector2>` start=Vector2( 0, 0 ), :ref:`Vector2<class_Vector2>` end=Vector2( 0, 0 ) **)** |
  119. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | void | :ref:`update_dirty_quadrants<class_TileMap_method_update_dirty_quadrants>` **(** **)** |
  121. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`Vector2<class_Vector2>` | :ref:`world_to_map<class_TileMap_method_world_to_map>` **(** :ref:`Vector2<class_Vector2>` world_position **)** |const| |
  123. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. .. rst-class:: classref-section-separator
  125. ----
  126. .. rst-class:: classref-descriptions-group
  127. Signals
  128. -------
  129. .. _class_TileMap_signal_settings_changed:
  130. .. rst-class:: classref-signal
  131. **settings_changed** **(** **)**
  132. Emitted when a tilemap setting has changed.
  133. .. rst-class:: classref-section-separator
  134. ----
  135. .. rst-class:: classref-descriptions-group
  136. Enumerations
  137. ------------
  138. .. _enum_TileMap_Mode:
  139. .. rst-class:: classref-enumeration
  140. enum **Mode**:
  141. .. _class_TileMap_constant_MODE_SQUARE:
  142. .. rst-class:: classref-enumeration-constant
  143. :ref:`Mode<enum_TileMap_Mode>` **MODE_SQUARE** = ``0``
  144. Orthogonal orientation mode.
  145. .. _class_TileMap_constant_MODE_ISOMETRIC:
  146. .. rst-class:: classref-enumeration-constant
  147. :ref:`Mode<enum_TileMap_Mode>` **MODE_ISOMETRIC** = ``1``
  148. Isometric orientation mode.
  149. .. _class_TileMap_constant_MODE_CUSTOM:
  150. .. rst-class:: classref-enumeration-constant
  151. :ref:`Mode<enum_TileMap_Mode>` **MODE_CUSTOM** = ``2``
  152. Custom orientation mode.
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. _enum_TileMap_HalfOffset:
  156. .. rst-class:: classref-enumeration
  157. enum **HalfOffset**:
  158. .. _class_TileMap_constant_HALF_OFFSET_X:
  159. .. rst-class:: classref-enumeration-constant
  160. :ref:`HalfOffset<enum_TileMap_HalfOffset>` **HALF_OFFSET_X** = ``0``
  161. Half offset on the X coordinate.
  162. .. _class_TileMap_constant_HALF_OFFSET_Y:
  163. .. rst-class:: classref-enumeration-constant
  164. :ref:`HalfOffset<enum_TileMap_HalfOffset>` **HALF_OFFSET_Y** = ``1``
  165. Half offset on the Y coordinate.
  166. .. _class_TileMap_constant_HALF_OFFSET_DISABLED:
  167. .. rst-class:: classref-enumeration-constant
  168. :ref:`HalfOffset<enum_TileMap_HalfOffset>` **HALF_OFFSET_DISABLED** = ``2``
  169. Half offset disabled.
  170. .. _class_TileMap_constant_HALF_OFFSET_NEGATIVE_X:
  171. .. rst-class:: classref-enumeration-constant
  172. :ref:`HalfOffset<enum_TileMap_HalfOffset>` **HALF_OFFSET_NEGATIVE_X** = ``3``
  173. Half offset on the X coordinate (negative).
  174. .. _class_TileMap_constant_HALF_OFFSET_NEGATIVE_Y:
  175. .. rst-class:: classref-enumeration-constant
  176. :ref:`HalfOffset<enum_TileMap_HalfOffset>` **HALF_OFFSET_NEGATIVE_Y** = ``4``
  177. Half offset on the Y coordinate (negative).
  178. .. rst-class:: classref-item-separator
  179. ----
  180. .. _enum_TileMap_TileOrigin:
  181. .. rst-class:: classref-enumeration
  182. enum **TileOrigin**:
  183. .. _class_TileMap_constant_TILE_ORIGIN_TOP_LEFT:
  184. .. rst-class:: classref-enumeration-constant
  185. :ref:`TileOrigin<enum_TileMap_TileOrigin>` **TILE_ORIGIN_TOP_LEFT** = ``0``
  186. Tile origin at its top-left corner.
  187. .. _class_TileMap_constant_TILE_ORIGIN_CENTER:
  188. .. rst-class:: classref-enumeration-constant
  189. :ref:`TileOrigin<enum_TileMap_TileOrigin>` **TILE_ORIGIN_CENTER** = ``1``
  190. Tile origin at its center.
  191. .. _class_TileMap_constant_TILE_ORIGIN_BOTTOM_LEFT:
  192. .. rst-class:: classref-enumeration-constant
  193. :ref:`TileOrigin<enum_TileMap_TileOrigin>` **TILE_ORIGIN_BOTTOM_LEFT** = ``2``
  194. Tile origin at its bottom-left corner.
  195. .. rst-class:: classref-section-separator
  196. ----
  197. .. rst-class:: classref-descriptions-group
  198. Constants
  199. ---------
  200. .. _class_TileMap_constant_INVALID_CELL:
  201. .. rst-class:: classref-constant
  202. **INVALID_CELL** = ``-1``
  203. Returned when a cell doesn't exist.
  204. .. rst-class:: classref-section-separator
  205. ----
  206. .. rst-class:: classref-descriptions-group
  207. Property Descriptions
  208. ---------------------
  209. .. _class_TileMap_property_bake_navigation:
  210. .. rst-class:: classref-property
  211. :ref:`bool<class_bool>` **bake_navigation** = ``false``
  212. .. rst-class:: classref-property-setget
  213. - void **set_bake_navigation** **(** :ref:`bool<class_bool>` value **)**
  214. - :ref:`bool<class_bool>` **is_baking_navigation** **(** **)**
  215. If ``true``, this TileMap bakes a navigation region.
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_TileMap_property_cell_clip_uv:
  219. .. rst-class:: classref-property
  220. :ref:`bool<class_bool>` **cell_clip_uv** = ``false``
  221. .. rst-class:: classref-property-setget
  222. - void **set_clip_uv** **(** :ref:`bool<class_bool>` value **)**
  223. - :ref:`bool<class_bool>` **get_clip_uv** **(** **)**
  224. If ``true``, the cell's UVs will be clipped.
  225. .. rst-class:: classref-item-separator
  226. ----
  227. .. _class_TileMap_property_cell_custom_transform:
  228. .. rst-class:: classref-property
  229. :ref:`Transform2D<class_Transform2D>` **cell_custom_transform** = ``Transform2D( 64, 0, 0, 64, 0, 0 )``
  230. .. rst-class:: classref-property-setget
  231. - void **set_custom_transform** **(** :ref:`Transform2D<class_Transform2D>` value **)**
  232. - :ref:`Transform2D<class_Transform2D>` **get_custom_transform** **(** **)**
  233. The custom :ref:`Transform2D<class_Transform2D>` to be applied to the TileMap's cells.
  234. .. rst-class:: classref-item-separator
  235. ----
  236. .. _class_TileMap_property_cell_half_offset:
  237. .. rst-class:: classref-property
  238. :ref:`HalfOffset<enum_TileMap_HalfOffset>` **cell_half_offset** = ``2``
  239. .. rst-class:: classref-property-setget
  240. - void **set_half_offset** **(** :ref:`HalfOffset<enum_TileMap_HalfOffset>` value **)**
  241. - :ref:`HalfOffset<enum_TileMap_HalfOffset>` **get_half_offset** **(** **)**
  242. Amount to offset alternating tiles. See :ref:`HalfOffset<enum_TileMap_HalfOffset>` for possible values.
  243. .. rst-class:: classref-item-separator
  244. ----
  245. .. _class_TileMap_property_cell_quadrant_size:
  246. .. rst-class:: classref-property
  247. :ref:`int<class_int>` **cell_quadrant_size** = ``16``
  248. .. rst-class:: classref-property-setget
  249. - void **set_quadrant_size** **(** :ref:`int<class_int>` value **)**
  250. - :ref:`int<class_int>` **get_quadrant_size** **(** **)**
  251. The TileMap's quadrant size. Optimizes drawing by batching, using chunks of this size.
  252. .. rst-class:: classref-item-separator
  253. ----
  254. .. _class_TileMap_property_cell_size:
  255. .. rst-class:: classref-property
  256. :ref:`Vector2<class_Vector2>` **cell_size** = ``Vector2( 64, 64 )``
  257. .. rst-class:: classref-property-setget
  258. - void **set_cell_size** **(** :ref:`Vector2<class_Vector2>` value **)**
  259. - :ref:`Vector2<class_Vector2>` **get_cell_size** **(** **)**
  260. The TileMap's cell size.
  261. .. rst-class:: classref-item-separator
  262. ----
  263. .. _class_TileMap_property_cell_tile_origin:
  264. .. rst-class:: classref-property
  265. :ref:`TileOrigin<enum_TileMap_TileOrigin>` **cell_tile_origin** = ``0``
  266. .. rst-class:: classref-property-setget
  267. - void **set_tile_origin** **(** :ref:`TileOrigin<enum_TileMap_TileOrigin>` value **)**
  268. - :ref:`TileOrigin<enum_TileMap_TileOrigin>` **get_tile_origin** **(** **)**
  269. Position for tile origin. See :ref:`TileOrigin<enum_TileMap_TileOrigin>` for possible values.
  270. .. rst-class:: classref-item-separator
  271. ----
  272. .. _class_TileMap_property_cell_y_sort:
  273. .. rst-class:: classref-property
  274. :ref:`bool<class_bool>` **cell_y_sort** = ``false``
  275. .. rst-class:: classref-property-setget
  276. - void **set_y_sort_mode** **(** :ref:`bool<class_bool>` value **)**
  277. - :ref:`bool<class_bool>` **is_y_sort_mode_enabled** **(** **)**
  278. If ``true``, the TileMap's direct children will be drawn in order of their Y coordinate.
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_TileMap_property_centered_textures:
  282. .. rst-class:: classref-property
  283. :ref:`bool<class_bool>` **centered_textures** = ``false``
  284. .. rst-class:: classref-property-setget
  285. - void **set_centered_textures** **(** :ref:`bool<class_bool>` value **)**
  286. - :ref:`bool<class_bool>` **is_centered_textures_enabled** **(** **)**
  287. If ``true``, the textures will be centered in the middle of each tile. This is useful for certain isometric or top-down modes when textures are made larger or smaller than the tiles (e.g. to avoid flickering on tile edges). The offset is still applied, but from the center of the tile. If used, :ref:`compatibility_mode<class_TileMap_property_compatibility_mode>` is ignored.
  288. If ``false``, the texture position start in the top-left corner unless :ref:`compatibility_mode<class_TileMap_property_compatibility_mode>` is enabled.
  289. .. rst-class:: classref-item-separator
  290. ----
  291. .. _class_TileMap_property_collision_bounce:
  292. .. rst-class:: classref-property
  293. :ref:`float<class_float>` **collision_bounce** = ``0.0``
  294. .. rst-class:: classref-property-setget
  295. - void **set_collision_bounce** **(** :ref:`float<class_float>` value **)**
  296. - :ref:`float<class_float>` **get_collision_bounce** **(** **)**
  297. Bounce value for static body collisions (see ``collision_use_kinematic``).
  298. .. rst-class:: classref-item-separator
  299. ----
  300. .. _class_TileMap_property_collision_friction:
  301. .. rst-class:: classref-property
  302. :ref:`float<class_float>` **collision_friction** = ``1.0``
  303. .. rst-class:: classref-property-setget
  304. - void **set_collision_friction** **(** :ref:`float<class_float>` value **)**
  305. - :ref:`float<class_float>` **get_collision_friction** **(** **)**
  306. Friction value for static body collisions (see ``collision_use_kinematic``).
  307. .. rst-class:: classref-item-separator
  308. ----
  309. .. _class_TileMap_property_collision_layer:
  310. .. rst-class:: classref-property
  311. :ref:`int<class_int>` **collision_layer** = ``1``
  312. .. rst-class:: classref-property-setget
  313. - void **set_collision_layer** **(** :ref:`int<class_int>` value **)**
  314. - :ref:`int<class_int>` **get_collision_layer** **(** **)**
  315. The collision layer(s) for all colliders in the TileMap. See `Collision layers and masks <../tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information.
  316. .. rst-class:: classref-item-separator
  317. ----
  318. .. _class_TileMap_property_collision_mask:
  319. .. rst-class:: classref-property
  320. :ref:`int<class_int>` **collision_mask** = ``1``
  321. .. rst-class:: classref-property-setget
  322. - void **set_collision_mask** **(** :ref:`int<class_int>` value **)**
  323. - :ref:`int<class_int>` **get_collision_mask** **(** **)**
  324. The collision mask(s) for all colliders in the TileMap. See `Collision layers and masks <../tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information.
  325. .. rst-class:: classref-item-separator
  326. ----
  327. .. _class_TileMap_property_collision_use_kinematic:
  328. .. rst-class:: classref-property
  329. :ref:`bool<class_bool>` **collision_use_kinematic** = ``false``
  330. .. rst-class:: classref-property-setget
  331. - void **set_collision_use_kinematic** **(** :ref:`bool<class_bool>` value **)**
  332. - :ref:`bool<class_bool>` **get_collision_use_kinematic** **(** **)**
  333. If ``true``, TileMap collisions will be handled as a kinematic body. If ``false``, collisions will be handled as static body.
  334. .. rst-class:: classref-item-separator
  335. ----
  336. .. _class_TileMap_property_collision_use_parent:
  337. .. rst-class:: classref-property
  338. :ref:`bool<class_bool>` **collision_use_parent** = ``false``
  339. .. rst-class:: classref-property-setget
  340. - void **set_collision_use_parent** **(** :ref:`bool<class_bool>` value **)**
  341. - :ref:`bool<class_bool>` **get_collision_use_parent** **(** **)**
  342. If ``true``, this tilemap's collision shape will be added to the collision shape of the parent. The parent has to be a :ref:`CollisionObject2D<class_CollisionObject2D>`.
  343. .. rst-class:: classref-item-separator
  344. ----
  345. .. _class_TileMap_property_compatibility_mode:
  346. .. rst-class:: classref-property
  347. :ref:`bool<class_bool>` **compatibility_mode** = ``false``
  348. .. rst-class:: classref-property-setget
  349. - void **set_compatibility_mode** **(** :ref:`bool<class_bool>` value **)**
  350. - :ref:`bool<class_bool>` **is_compatibility_mode_enabled** **(** **)**
  351. If ``true``, the compatibility with the tilemaps made in Godot 3.1 or earlier is maintained (textures move when the tile origin changes and rotate if the texture size is not homogeneous). This mode presents problems when doing ``flip_h``, ``flip_v`` and ``transpose`` tile operations on non-homogeneous isometric tiles (e.g. 2:1), in which the texture could not coincide with the collision, thus it is not recommended for isometric or non-square tiles.
  352. If ``false``, the textures do not move when doing ``flip_h``, ``flip_v`` operations if no offset is used, nor when changing the tile origin.
  353. The compatibility mode doesn't work with the :ref:`centered_textures<class_TileMap_property_centered_textures>` option, because displacing textures with the :ref:`cell_tile_origin<class_TileMap_property_cell_tile_origin>` option or in irregular tiles is not relevant when centering those textures.
  354. .. rst-class:: classref-item-separator
  355. ----
  356. .. _class_TileMap_property_mode:
  357. .. rst-class:: classref-property
  358. :ref:`Mode<enum_TileMap_Mode>` **mode** = ``0``
  359. .. rst-class:: classref-property-setget
  360. - void **set_mode** **(** :ref:`Mode<enum_TileMap_Mode>` value **)**
  361. - :ref:`Mode<enum_TileMap_Mode>` **get_mode** **(** **)**
  362. The TileMap orientation mode. See :ref:`Mode<enum_TileMap_Mode>` for possible values.
  363. .. rst-class:: classref-item-separator
  364. ----
  365. .. _class_TileMap_property_navigation_layers:
  366. .. rst-class:: classref-property
  367. :ref:`int<class_int>` **navigation_layers** = ``1``
  368. .. rst-class:: classref-property-setget
  369. - void **set_navigation_layers** **(** :ref:`int<class_int>` value **)**
  370. - :ref:`int<class_int>` **get_navigation_layers** **(** **)**
  371. The navigation layers the TileMap generates its navigation regions in.
  372. .. rst-class:: classref-item-separator
  373. ----
  374. .. _class_TileMap_property_occluder_light_mask:
  375. .. rst-class:: classref-property
  376. :ref:`int<class_int>` **occluder_light_mask** = ``1``
  377. .. rst-class:: classref-property-setget
  378. - void **set_occluder_light_mask** **(** :ref:`int<class_int>` value **)**
  379. - :ref:`int<class_int>` **get_occluder_light_mask** **(** **)**
  380. The light mask assigned to all light occluders in the TileMap. The TileSet's light occluders will cast shadows only from Light2D(s) that have the same light mask(s).
  381. .. rst-class:: classref-item-separator
  382. ----
  383. .. _class_TileMap_property_show_collision:
  384. .. rst-class:: classref-property
  385. :ref:`bool<class_bool>` **show_collision** = ``false``
  386. .. rst-class:: classref-property-setget
  387. - void **set_show_collision** **(** :ref:`bool<class_bool>` value **)**
  388. - :ref:`bool<class_bool>` **is_show_collision_enabled** **(** **)**
  389. If ``true``, collision shapes are visible in the editor. Doesn't affect collision shapes visibility at runtime. To show collision shapes at runtime, enable **Visible Collision Shapes** in the **Debug** menu instead.
  390. .. rst-class:: classref-item-separator
  391. ----
  392. .. _class_TileMap_property_tile_set:
  393. .. rst-class:: classref-property
  394. :ref:`TileSet<class_TileSet>` **tile_set**
  395. .. rst-class:: classref-property-setget
  396. - void **set_tileset** **(** :ref:`TileSet<class_TileSet>` value **)**
  397. - :ref:`TileSet<class_TileSet>` **get_tileset** **(** **)**
  398. The assigned :ref:`TileSet<class_TileSet>`.
  399. .. rst-class:: classref-section-separator
  400. ----
  401. .. rst-class:: classref-descriptions-group
  402. Method Descriptions
  403. -------------------
  404. .. _class_TileMap_method_clear:
  405. .. rst-class:: classref-method
  406. void **clear** **(** **)**
  407. Clears all cells.
  408. .. rst-class:: classref-item-separator
  409. ----
  410. .. _class_TileMap_method_fix_invalid_tiles:
  411. .. rst-class:: classref-method
  412. void **fix_invalid_tiles** **(** **)**
  413. Clears cells that do not exist in the tileset.
  414. .. rst-class:: classref-item-separator
  415. ----
  416. .. _class_TileMap_method_get_cell:
  417. .. rst-class:: classref-method
  418. :ref:`int<class_int>` **get_cell** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const|
  419. Returns the tile index of the given cell. If no tile exists in the cell, returns :ref:`INVALID_CELL<class_TileMap_constant_INVALID_CELL>`.
  420. .. rst-class:: classref-item-separator
  421. ----
  422. .. _class_TileMap_method_get_cell_autotile_coord:
  423. .. rst-class:: classref-method
  424. :ref:`Vector2<class_Vector2>` **get_cell_autotile_coord** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const|
  425. Returns the coordinate (subtile column and row) of the autotile variation in the tileset. Returns a zero vector if the cell doesn't have autotiling.
  426. .. rst-class:: classref-item-separator
  427. ----
  428. .. _class_TileMap_method_get_cellv:
  429. .. rst-class:: classref-method
  430. :ref:`int<class_int>` **get_cellv** **(** :ref:`Vector2<class_Vector2>` position **)** |const|
  431. Returns the tile index of the cell given by a Vector2. If no tile exists in the cell, returns :ref:`INVALID_CELL<class_TileMap_constant_INVALID_CELL>`.
  432. .. rst-class:: classref-item-separator
  433. ----
  434. .. _class_TileMap_method_get_collision_layer_bit:
  435. .. rst-class:: classref-method
  436. :ref:`bool<class_bool>` **get_collision_layer_bit** **(** :ref:`int<class_int>` bit **)** |const|
  437. Returns ``true`` if the given collision layer bit is set.
  438. .. rst-class:: classref-item-separator
  439. ----
  440. .. _class_TileMap_method_get_collision_mask_bit:
  441. .. rst-class:: classref-method
  442. :ref:`bool<class_bool>` **get_collision_mask_bit** **(** :ref:`int<class_int>` bit **)** |const|
  443. Returns ``true`` if the given collision mask bit is set.
  444. .. rst-class:: classref-item-separator
  445. ----
  446. .. _class_TileMap_method_get_used_cells:
  447. .. rst-class:: classref-method
  448. :ref:`Array<class_Array>` **get_used_cells** **(** **)** |const|
  449. Returns a :ref:`Vector2<class_Vector2>` array with the positions of all cells containing a tile from the tileset (i.e. a tile index different from ``-1``).
  450. .. rst-class:: classref-item-separator
  451. ----
  452. .. _class_TileMap_method_get_used_cells_by_id:
  453. .. rst-class:: classref-method
  454. :ref:`Array<class_Array>` **get_used_cells_by_id** **(** :ref:`int<class_int>` id **)** |const|
  455. Returns an array of all cells with the given tile index specified in ``id``.
  456. .. rst-class:: classref-item-separator
  457. ----
  458. .. _class_TileMap_method_get_used_rect:
  459. .. rst-class:: classref-method
  460. :ref:`Rect2<class_Rect2>` **get_used_rect** **(** **)**
  461. Returns a rectangle enclosing the used (non-empty) tiles of the map.
  462. .. rst-class:: classref-item-separator
  463. ----
  464. .. _class_TileMap_method_is_cell_transposed:
  465. .. rst-class:: classref-method
  466. :ref:`bool<class_bool>` **is_cell_transposed** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const|
  467. Returns ``true`` if the given cell is transposed, i.e. the X and Y axes are swapped.
  468. .. rst-class:: classref-item-separator
  469. ----
  470. .. _class_TileMap_method_is_cell_x_flipped:
  471. .. rst-class:: classref-method
  472. :ref:`bool<class_bool>` **is_cell_x_flipped** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const|
  473. Returns ``true`` if the given cell is flipped in the X axis.
  474. .. rst-class:: classref-item-separator
  475. ----
  476. .. _class_TileMap_method_is_cell_y_flipped:
  477. .. rst-class:: classref-method
  478. :ref:`bool<class_bool>` **is_cell_y_flipped** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const|
  479. Returns ``true`` if the given cell is flipped in the Y axis.
  480. .. rst-class:: classref-item-separator
  481. ----
  482. .. _class_TileMap_method_map_to_world:
  483. .. rst-class:: classref-method
  484. :ref:`Vector2<class_Vector2>` **map_to_world** **(** :ref:`Vector2<class_Vector2>` map_position, :ref:`bool<class_bool>` ignore_half_ofs=false **)** |const|
  485. Returns the local position of the top left corner of the cell corresponding to the given tilemap (grid-based) coordinates.
  486. To get the global position, use :ref:`Node2D.to_global<class_Node2D_method_to_global>`:
  487. ::
  488. var local_position = my_tilemap.map_to_world(map_position)
  489. var global_position = my_tilemap.to_global(local_position)
  490. Optionally, the tilemap's half offset can be ignored.
  491. .. rst-class:: classref-item-separator
  492. ----
  493. .. _class_TileMap_method_set_cell:
  494. .. rst-class:: classref-method
  495. void **set_cell** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` tile, :ref:`bool<class_bool>` flip_x=false, :ref:`bool<class_bool>` flip_y=false, :ref:`bool<class_bool>` transpose=false, :ref:`Vector2<class_Vector2>` autotile_coord=Vector2( 0, 0 ) **)**
  496. Sets the tile index for the given cell.
  497. An index of ``-1`` clears the cell.
  498. Optionally, the tile can also be flipped, transposed, or given autotile coordinates. The autotile coordinate refers to the column and row of the subtile.
  499. \ **Note:** Data such as navigation polygons and collision shapes are not immediately updated for performance reasons.
  500. If you need these to be immediately updated, you can call :ref:`update_dirty_quadrants<class_TileMap_method_update_dirty_quadrants>`.
  501. Overriding this method also overrides it internally, allowing custom logic to be implemented when tiles are placed/removed:
  502. ::
  503. func set_cell(x, y, tile, flip_x=false, flip_y=false, transpose=false, autotile_coord=Vector2()):
  504. # Write your custom logic here.
  505. # To call the default method:
  506. .set_cell(x, y, tile, flip_x, flip_y, transpose, autotile_coord)
  507. .. rst-class:: classref-item-separator
  508. ----
  509. .. _class_TileMap_method_set_cellv:
  510. .. rst-class:: classref-method
  511. void **set_cellv** **(** :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` tile, :ref:`bool<class_bool>` flip_x=false, :ref:`bool<class_bool>` flip_y=false, :ref:`bool<class_bool>` transpose=false, :ref:`Vector2<class_Vector2>` autotile_coord=Vector2( 0, 0 ) **)**
  512. Sets the tile index for the cell given by a Vector2.
  513. An index of ``-1`` clears the cell.
  514. Optionally, the tile can also be flipped, transposed, or given autotile coordinates. The autotile coordinate refers to the column and row of the subtile.
  515. \ **Note:** Data such as navigation polygons and collision shapes are not immediately updated for performance reasons.
  516. If you need these to be immediately updated, you can call :ref:`update_dirty_quadrants<class_TileMap_method_update_dirty_quadrants>`.
  517. .. rst-class:: classref-item-separator
  518. ----
  519. .. _class_TileMap_method_set_collision_layer_bit:
  520. .. rst-class:: classref-method
  521. void **set_collision_layer_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  522. Sets the given collision layer bit.
  523. .. rst-class:: classref-item-separator
  524. ----
  525. .. _class_TileMap_method_set_collision_mask_bit:
  526. .. rst-class:: classref-method
  527. void **set_collision_mask_bit** **(** :ref:`int<class_int>` bit, :ref:`bool<class_bool>` value **)**
  528. Sets the given collision mask bit.
  529. .. rst-class:: classref-item-separator
  530. ----
  531. .. _class_TileMap_method_update_bitmask_area:
  532. .. rst-class:: classref-method
  533. void **update_bitmask_area** **(** :ref:`Vector2<class_Vector2>` position **)**
  534. Applies autotiling rules to the cell (and its adjacent cells) referenced by its grid-based X and Y coordinates.
  535. .. rst-class:: classref-item-separator
  536. ----
  537. .. _class_TileMap_method_update_bitmask_region:
  538. .. rst-class:: classref-method
  539. void **update_bitmask_region** **(** :ref:`Vector2<class_Vector2>` start=Vector2( 0, 0 ), :ref:`Vector2<class_Vector2>` end=Vector2( 0, 0 ) **)**
  540. Applies autotiling rules to the cells in the given region (specified by grid-based X and Y coordinates).
  541. Calling with invalid (or missing) parameters applies autotiling rules for the entire tilemap.
  542. .. rst-class:: classref-item-separator
  543. ----
  544. .. _class_TileMap_method_update_dirty_quadrants:
  545. .. rst-class:: classref-method
  546. void **update_dirty_quadrants** **(** **)**
  547. Updates the tile map's quadrants, allowing things such as navigation and collision shapes to be immediately used if modified.
  548. .. rst-class:: classref-item-separator
  549. ----
  550. .. _class_TileMap_method_world_to_map:
  551. .. rst-class:: classref-method
  552. :ref:`Vector2<class_Vector2>` **world_to_map** **(** :ref:`Vector2<class_Vector2>` world_position **)** |const|
  553. Returns the tilemap (grid-based) coordinates corresponding to the given local position.
  554. To use this with a global position, first determine the local position with :ref:`Node2D.to_local<class_Node2D_method_to_local>`:
  555. ::
  556. var local_position = my_tilemap.to_local(global_position)
  557. var map_position = my_tilemap.world_to_map(local_position)
  558. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  559. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  560. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  561. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`