TileMap.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="TileMap" inherits="Node2D" version="4.0">
  3. <brief_description>
  4. Node for 2D tile-based maps.
  5. </brief_description>
  6. <description>
  7. Node for 2D tile-based maps. Tilemaps use a [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.
  8. </description>
  9. <tutorials>
  10. <link title="Using Tilemaps">https://docs.godotengine.org/en/latest/tutorials/2d/using_tilemaps.html</link>
  11. <link title="2D Platformer Demo">https://godotengine.org/asset-library/asset/120</link>
  12. <link title="2D Isometric Demo">https://godotengine.org/asset-library/asset/112</link>
  13. <link title="2D Hexagonal Demo">https://godotengine.org/asset-library/asset/111</link>
  14. <link title="2D Navigation Astar Demo">https://godotengine.org/asset-library/asset/519</link>
  15. <link title="2D Role Playing Game Demo">https://godotengine.org/asset-library/asset/520</link>
  16. <link title="2D Kinematic Character Demo">https://godotengine.org/asset-library/asset/113</link>
  17. </tutorials>
  18. <methods>
  19. <method name="_tile_data_runtime_update" qualifiers="virtual">
  20. <return type="void" />
  21. <argument index="0" name="layer" type="int" />
  22. <argument index="1" name="coords" type="Vector2i" />
  23. <argument index="2" name="tile_data" type="TileData" />
  24. <description>
  25. Called with a TileData object about to be used internally by the TileMap, allowing its modification at runtime.
  26. This method is only called if [method _use_tile_data_runtime_update] is implemented and returns [code]true[/code] for the given tile [code]coords[/coords] and [code]layer[/code].
  27. [b]Warning:[/b] The [code]tile_data[/code] 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.
  28. [b]Note:[/b] If the properties of [code]tile_data[/code] object should change over time, use [method force_update] to trigger a TileMap update.
  29. </description>
  30. </method>
  31. <method name="_use_tile_data_runtime_update" qualifiers="virtual">
  32. <return type="bool" />
  33. <argument index="0" name="layer" type="int" />
  34. <argument index="1" name="coords" type="Vector2i" />
  35. <description>
  36. Should return [code]true[/code] if the tile at coordinates [code]coords[/coords] on layer [code]layer[/code] requires a runtime update.
  37. [b]Warning:[/b] Make sure this function only return [code]true[/code] when needed. Any tile processed at runtime without a need for it will imply a significant performance penalty.
  38. </description>
  39. </method>
  40. <method name="add_layer">
  41. <return type="void" />
  42. <argument index="0" name="to_position" type="int" />
  43. <description>
  44. Adds a layer at the given position [code]to_position[/code] in the array. If [code]to_position[/code] is -1, adds it at the end of the array.
  45. </description>
  46. </method>
  47. <method name="clear">
  48. <return type="void" />
  49. <description>
  50. Clears all cells.
  51. </description>
  52. </method>
  53. <method name="clear_layer">
  54. <return type="void" />
  55. <argument index="0" name="layer" type="int" />
  56. <description>
  57. Clears all cells on the given layer.
  58. </description>
  59. </method>
  60. <method name="fix_invalid_tiles">
  61. <return type="void" />
  62. <description>
  63. Clears cells that do not exist in the tileset.
  64. </description>
  65. </method>
  66. <method name="force_update">
  67. <return type="void" />
  68. <argument index="0" name="layer" type="int" default="-1" />
  69. <description>
  70. Triggers an update of the TileMap. If [code]layer[/code] is provided, only updates the given layer.
  71. [b]Note:[/b] The TileMap node updates automatically when one of its properties is modified. A manual update is only needed if runtime modifications (implemented in [method _tile_data_runtime_update]) need to be applied.
  72. [b]Warning:[/b] Updating the TileMap is a performance demanding task. Limit occurences of those updates to the minimum and limit the amount tiles they impact (by segregating tiles updated often to a dedicated layer for example).
  73. </description>
  74. </method>
  75. <method name="get_cell_alternative_tile" qualifiers="const">
  76. <return type="int" />
  77. <argument index="0" name="layer" type="int" />
  78. <argument index="1" name="coords" type="Vector2i" />
  79. <argument index="2" name="use_proxies" type="bool" />
  80. <description>
  81. Returns the tile alternative ID of the cell on layer [code]layer[/code] at [code]coords[/code]. If [code]use_proxies[/code] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
  82. </description>
  83. </method>
  84. <method name="get_cell_atlas_coords" qualifiers="const">
  85. <return type="Vector2i" />
  86. <argument index="0" name="layer" type="int" />
  87. <argument index="1" name="coords" type="Vector2i" />
  88. <argument index="2" name="use_proxies" type="bool" />
  89. <description>
  90. Returns the tile atlas coordinates ID of the cell on layer [code]layer[/code] at coordinates [code]coords[/code]. If [code]use_proxies[/code] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
  91. </description>
  92. </method>
  93. <method name="get_cell_source_id" qualifiers="const">
  94. <return type="int" />
  95. <argument index="0" name="layer" type="int" />
  96. <argument index="1" name="coords" type="Vector2i" />
  97. <argument index="2" name="use_proxies" type="bool" />
  98. <description>
  99. Returns the tile source ID of the cell on layer [code]layer[/code] at coordinates [code]coords[/code]. If [code]use_proxies[/code] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
  100. </description>
  101. </method>
  102. <method name="get_coords_for_body_rid">
  103. <return type="Vector2i" />
  104. <argument index="0" name="body" type="RID" />
  105. <description>
  106. Returns the coodinates of the tile for given physics body RID. Such RID can be retrieved from [method KinematicCollision2D.get_collider_rid], when colliding with a tile.
  107. </description>
  108. </method>
  109. <method name="get_layer_modulate" qualifiers="const">
  110. <return type="Color" />
  111. <argument index="0" name="layer" type="int" />
  112. <description>
  113. Returns a TileMap layer's modulate.
  114. </description>
  115. </method>
  116. <method name="get_layer_name" qualifiers="const">
  117. <return type="String" />
  118. <argument index="0" name="layer" type="int" />
  119. <description>
  120. Returns a TileMap layer's name.
  121. </description>
  122. </method>
  123. <method name="get_layer_y_sort_origin" qualifiers="const">
  124. <return type="int" />
  125. <argument index="0" name="layer" type="int" />
  126. <description>
  127. Returns a TileMap layer's Y sort origin.
  128. </description>
  129. </method>
  130. <method name="get_layer_z_index" qualifiers="const">
  131. <return type="int" />
  132. <argument index="0" name="layer" type="int" />
  133. <description>
  134. Returns a TileMap layer's Z-index value.
  135. </description>
  136. </method>
  137. <method name="get_layers_count" qualifiers="const">
  138. <return type="int" />
  139. <description>
  140. </description>
  141. </method>
  142. <method name="get_neighbor_cell" qualifiers="const">
  143. <return type="Vector2i" />
  144. <argument index="0" name="coords" type="Vector2i" />
  145. <argument index="1" name="neighbor" type="int" enum="TileSet.CellNeighbor" />
  146. <description>
  147. Returns the neighboring cell to the one at coordinates [code]coords[/code], indentified by the [code]neighbor[/code] direction. This method takes into account the different layouts a TileMap can take.
  148. </description>
  149. </method>
  150. <method name="get_pattern">
  151. <return type="TileMapPattern" />
  152. <argument index="0" name="layer" type="int" />
  153. <argument index="1" name="coords_array" type="Vector2i[]" />
  154. <description>
  155. Creates a new [TileMapPattern] from the given layer and set of cells.
  156. </description>
  157. </method>
  158. <method name="get_surrounding_tiles">
  159. <return type="Vector2i[]" />
  160. <argument index="0" name="coords" type="Vector2i" />
  161. <description>
  162. Returns the list of all neighbourings cells to the one at [code]coords[/code]
  163. </description>
  164. </method>
  165. <method name="get_used_cells" qualifiers="const">
  166. <return type="Vector2i[]" />
  167. <argument index="0" name="layer" type="int" />
  168. <description>
  169. Returns a [Vector2] array with the positions of all cells containing a tile in the given layer. A cell is considered empty if its source identifier equals -1, its atlas coordinates identifiers is [code]Vector2(-1, -1)[/code] and its alternative identifier is -1.
  170. </description>
  171. </method>
  172. <method name="get_used_rect">
  173. <return type="Rect2" />
  174. <description>
  175. Returns a rectangle enclosing the used (non-empty) tiles of the map, including all layers.
  176. </description>
  177. </method>
  178. <method name="is_layer_enabled" qualifiers="const">
  179. <return type="bool" />
  180. <argument index="0" name="layer" type="int" />
  181. <description>
  182. Returns if a layer is enabled.
  183. </description>
  184. </method>
  185. <method name="is_layer_y_sort_enabled" qualifiers="const">
  186. <return type="bool" />
  187. <argument index="0" name="layer" type="int" />
  188. <description>
  189. Returns if a layer Y-sorts its tiles.
  190. </description>
  191. </method>
  192. <method name="map_pattern">
  193. <return type="Vector2i" />
  194. <argument index="0" name="position_in_tilemap" type="Vector2i" />
  195. <argument index="1" name="coords_in_pattern" type="Vector2i" />
  196. <argument index="2" name="pattern" type="TileMapPattern" />
  197. <description>
  198. Returns for the given coodinate [code]coords_in_pattern[/code] in a [TileMapPattern] the corresponding cell coordinates if the pattern was pasted at the [code]position_in_tilemap[/code] coordinates (see [method set_pattern]). This mapping is required as in half-offset tile shapes, the mapping might not work by calculating [code]position_in_tile_map + coords_in_pattern[/code]
  199. </description>
  200. </method>
  201. <method name="map_to_world" qualifiers="const">
  202. <return type="Vector2" />
  203. <argument index="0" name="map_position" type="Vector2i" />
  204. <description>
  205. Returns the local position corresponding to the given tilemap (grid-based) coordinates.
  206. </description>
  207. </method>
  208. <method name="move_layer">
  209. <return type="void" />
  210. <argument index="0" name="layer" type="int" />
  211. <argument index="1" name="to_position" type="int" />
  212. <description>
  213. Moves the layer at index [code]layer_index[/code] to the given position [code]to_position[/code] in the array.
  214. </description>
  215. </method>
  216. <method name="remove_layer">
  217. <return type="void" />
  218. <argument index="0" name="layer" type="int" />
  219. <description>
  220. Moves the layer at index [code]layer_index[/code] to the given position [code]to_position[/code] in the array.
  221. </description>
  222. </method>
  223. <method name="set_cell">
  224. <return type="void" />
  225. <argument index="0" name="layer" type="int" />
  226. <argument index="1" name="coords" type="Vector2i" />
  227. <argument index="2" name="source_id" type="int" default="-1" />
  228. <argument index="3" name="atlas_coords" type="Vector2i" default="Vector2i(-1, -1)" />
  229. <argument index="4" name="alternative_tile" type="int" default="-1" />
  230. <description>
  231. Sets the tile indentifiers for the cell on layer [code]layer[/code] at coordinates [code]coords[/code]. Each tile of the [TileSet] is identified using three parts:
  232. - The source indentifier [code]source_id[/code] identifies a [TileSetSource] identifier. See [method TileSet.set_source_id],
  233. - The atlas coordinates identifier [code]atlas_coords[/code] identifies a tile coordinates in the atlas (if the source is a [TileSetAtlasSource]. For [TileSetScenesCollectionSource] it should be 0),
  234. - The alternative tile identifier [code]alternative_tile[/code] identifies a tile alternative the source is a [TileSetAtlasSource], and the scene for a [TileSetScenesCollectionSource].
  235. </description>
  236. </method>
  237. <method name="set_cells_from_surrounding_terrains">
  238. <return type="void" />
  239. <argument index="0" name="layer" type="int" />
  240. <argument index="1" name="cells" type="Vector2i[]" />
  241. <argument index="2" name="terrain_set" type="int" />
  242. <argument index="3" name="ignore_empty_terrains" type="bool" default="true" />
  243. <description>
  244. Updates all the cells in the [code]cells[/code] coordinates array and replace them by tiles that matches the surrounding cells terrains. Only cells form the given [code]terrain_set[/code] are considered.
  245. If [code]ignore_empty_terrains[/code] is true, zones with no terrain defined are ignored to select the tiles.
  246. </description>
  247. </method>
  248. <method name="set_layer_enabled">
  249. <return type="void" />
  250. <argument index="0" name="layer" type="int" />
  251. <argument index="1" name="enabled" type="bool" />
  252. <description>
  253. Enables or disables the layer [code]layer[/code]. A disabled layer is not processed at all (no rendering, no physics, etc...).
  254. </description>
  255. </method>
  256. <method name="set_layer_modulate">
  257. <return type="void" />
  258. <argument index="0" name="layer" type="int" />
  259. <argument index="1" name="enabled" type="Color" />
  260. <description>
  261. Sets a layer's color. It will be multiplied by tile's color and TileMap's modulate.
  262. </description>
  263. </method>
  264. <method name="set_layer_name">
  265. <return type="void" />
  266. <argument index="0" name="layer" type="int" />
  267. <argument index="1" name="name" type="String" />
  268. <description>
  269. Sets a layer's name. This is mostly useful in the editor.
  270. </description>
  271. </method>
  272. <method name="set_layer_y_sort_enabled">
  273. <return type="void" />
  274. <argument index="0" name="layer" type="int" />
  275. <argument index="1" name="y_sort_enabled" type="bool" />
  276. <description>
  277. 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.
  278. Y-sorted layers should usually be on different Z-index values than not Y-sorted layers, otherwise, each of those layer will be Y-sorted as whole with the Y-sorted one. This is usually an undesired behvaior.
  279. </description>
  280. </method>
  281. <method name="set_layer_y_sort_origin">
  282. <return type="void" />
  283. <argument index="0" name="layer" type="int" />
  284. <argument index="1" name="y_sort_origin" type="int" />
  285. <description>
  286. Sets a layer's Y-sort origin value. This Y-sort origin value is added to each tile's Y-sort origin value.
  287. This allows, for example, to fake a different height level on each layer. This can be useful for top-down view games.
  288. </description>
  289. </method>
  290. <method name="set_layer_z_index">
  291. <return type="void" />
  292. <argument index="0" name="layer" type="int" />
  293. <argument index="1" name="z_index" type="int" />
  294. <description>
  295. Sets a layers Z-index value. This Z-index is added to each tile's Z-index value.
  296. </description>
  297. </method>
  298. <method name="set_pattern">
  299. <return type="void" />
  300. <argument index="0" name="layer" type="int" />
  301. <argument index="1" name="position" type="Vector2i" />
  302. <argument index="2" name="pattern" type="TileMapPattern" />
  303. <description>
  304. Paste the given [TileMapPattern] at the given [code]position[/code] and [code]layer[/code] in the tile map.
  305. </description>
  306. </method>
  307. <method name="world_to_map" qualifiers="const">
  308. <return type="Vector2i" />
  309. <argument index="0" name="world_position" type="Vector2" />
  310. <description>
  311. Returns the tilemap (grid-based) coordinates corresponding to the given local position.
  312. </description>
  313. </method>
  314. </methods>
  315. <members>
  316. <member name="cell_quadrant_size" type="int" setter="set_quadrant_size" getter="get_quadrant_size" default="16">
  317. The TileMap's quadrant size. Optimizes drawing by batching, using chunks of this size.
  318. </member>
  319. <member name="collision_animatable" type="bool" setter="set_collision_animatable" getter="is_collision_animatable" default="false">
  320. 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.
  321. [b]Note:[/b] Enabling [code]collision_animatable[/code] may have a small performance impact, only do it if the TileMap is moving and has colliding tiles.
  322. </member>
  323. <member name="collision_visibility_mode" type="int" setter="set_collision_visibility_mode" getter="get_collision_visibility_mode" enum="TileMap.VisibilityMode" default="0">
  324. Show or hide the TileMap's collision shapes. If set to [code]VISIBILITY_MODE_DEFAULT[/code], this depends on the show collision debug settings.
  325. </member>
  326. <member name="navigation_visibility_mode" type="int" setter="set_navigation_visibility_mode" getter="get_navigation_visibility_mode" enum="TileMap.VisibilityMode" default="0">
  327. Show or hide the TileMap's collision shapes. If set to [code]VISIBILITY_MODE_DEFAULT[/code], this depends on the show navigation debug settings.
  328. </member>
  329. <member name="tile_set" type="TileSet" setter="set_tileset" getter="get_tileset">
  330. The assigned [TileSet].
  331. </member>
  332. </members>
  333. <signals>
  334. <signal name="changed">
  335. <description>
  336. Emitted when the [TileSet] of this TileMap changes.
  337. </description>
  338. </signal>
  339. </signals>
  340. <constants>
  341. <constant name="VISIBILITY_MODE_DEFAULT" value="0" enum="VisibilityMode">
  342. Use the debug settings to determine visibility.
  343. </constant>
  344. <constant name="VISIBILITY_MODE_FORCE_HIDE" value="2" enum="VisibilityMode">
  345. Always hide.
  346. </constant>
  347. <constant name="VISIBILITY_MODE_FORCE_SHOW" value="1" enum="VisibilityMode">
  348. Always show.
  349. </constant>
  350. </constants>
  351. </class>