Debian Codegraph @

doc/classes/TileSetAtlasSource.xml

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <class name="TileSetAtlasSource" inherits="TileSetSource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 Exposes a 2D atlas texture as a set of tiles for a [TileSet] resource.
5 </brief_description>
6 <description>
7 An atlas is a grid of tiles laid out on a texture. Each tile in the grid must be exposed using [method create_tile]. Those tiles are then indexed using their coordinates in the grid.
8 Each tile can also have a size in the grid coordinates, making it more or less cells in the atlas.
9 Alternatives version of a tile can be created using [method create_alternative_tile], which are then indexed using an alternative ID. The main tile (the one in the grid), is accessed with an alternative ID equal to 0.
10 Each tile alternate has a set of properties that is defined by the source's [TileSet] layers. Those properties are stored in a TileData object that can be accessed and modified using [method get_tile_data].
11 As TileData properties are stored directly in the TileSetAtlasSource resource, their properties might also be set using [code]TileSetAtlasSource.set("&lt;coords_x&gt;:&lt;coords_y&gt;/&lt;alternative_id&gt;/&lt;tile_data_property&gt;")[/code].
12 </description>
13 <tutorials>
14 </tutorials>
15 <methods>
16 <method name="clear_tiles_outside_texture">
17 <return type="void" />
18 <description>
19 Removes all tiles that don't fit the available texture area. This method iterates over all the source's tiles, so it's advised to use [method has_tiles_outside_texture] beforehand.
20 </description>
21 </method>
22 <method name="create_alternative_tile">
23 <return type="int" />
24 <param index="0" name="atlas_coords" type="Vector2i" />
25 <param index="1" name="alternative_id_override" type="int" default="-1" />
26 <description>
27 Creates an alternative tile for the tile at coordinates [param atlas_coords]. If [param alternative_id_override] is -1, give it an automatically generated unique ID, or assigns it the given ID otherwise.
28 Returns the new alternative identifier, or -1 if the alternative could not be created with a provided [param alternative_id_override].
29 </description>
30 </method>
31 <method name="create_tile">
32 <return type="void" />
33 <param index="0" name="atlas_coords" type="Vector2i" />
34 <param index="1" name="size" type="Vector2i" default="Vector2i(1, 1)" />
35 <description>
36 Creates a new tile at coordinates [param atlas_coords] with the given [param size].
37 </description>
38 </method>
39 <method name="get_atlas_grid_size" qualifiers="const">
40 <return type="Vector2i" />
41 <description>
42 Returns the atlas grid size, which depends on how many tiles can fit in the texture. It thus depends on the [member texture]'s size, the atlas [member margins], and the tiles' [member texture_region_size].
43 </description>
44 </method>
45 <method name="get_next_alternative_tile_id" qualifiers="const">
46 <return type="int" />
47 <param index="0" name="atlas_coords" type="Vector2i" />
48 <description>
49 Returns the alternative ID a following call to [method create_alternative_tile] would return.
50 </description>
51 </method>
52 <method name="get_runtime_texture" qualifiers="const">
53 <return type="Texture2D" />
54 <description>
55 If [member use_texture_padding] is [code]false[/code], returns [member texture]. Otherwise, returns an internal [ImageTexture] created that includes the padding.
56 </description>
57 </method>
58 <method name="get_runtime_tile_texture_region" qualifiers="const">
59 <return type="Rect2i" />
60 <param index="0" name="atlas_coords" type="Vector2i" />
61 <param index="1" name="frame" type="int" />
62 <description>
63 Returns the region of the tile at coordinates [param atlas_coords] for the given [param frame] inside the texture returned by [method get_runtime_texture].
64 [b]Note:[/b] If [member use_texture_padding] is [code]false[/code], returns the same as [method get_tile_texture_region].
65 </description>
66 </method>
67 <method name="get_tile_animation_columns" qualifiers="const">
68 <return type="int" />
69 <param index="0" name="atlas_coords" type="Vector2i" />
70 <description>
71 Returns how many columns the tile at [param atlas_coords] has in its animation layout.
72 </description>
73 </method>
74 <method name="get_tile_animation_frame_duration" qualifiers="const">
75 <return type="float" />
76 <param index="0" name="atlas_coords" type="Vector2i" />
77 <param index="1" name="frame_index" type="int" />
78 <description>
79 Returns the animation frame duration of frame [param frame_index] for the tile at coordinates [param atlas_coords].
80 </description>
81 </method>
82 <method name="get_tile_animation_frames_count" qualifiers="const">
83 <return type="int" />
84 <param index="0" name="atlas_coords" type="Vector2i" />
85 <description>
86 Returns how many animation frames has the tile at coordinates [param atlas_coords].
87 </description>
88 </method>
89 <method name="get_tile_animation_mode" qualifiers="const">
90 <return type="int" enum="TileSetAtlasSource.TileAnimationMode" />
91 <param index="0" name="atlas_coords" type="Vector2i" />
92 <description>
93 Returns the tile animation mode of the tile at [param atlas_coords]. See also [method set_tile_animation_mode].
94 </description>
95 </method>
96 <method name="get_tile_animation_separation" qualifiers="const">
97 <return type="Vector2i" />
98 <param index="0" name="atlas_coords" type="Vector2i" />
99 <description>
100 Returns the separation (as in the atlas grid) between each frame of an animated tile at coordinates [param atlas_coords].
101 </description>
102 </method>
103 <method name="get_tile_animation_speed" qualifiers="const">
104 <return type="float" />
105 <param index="0" name="atlas_coords" type="Vector2i" />
106 <description>
107 Returns the animation speed of the tile at coordinates [param atlas_coords].
108 </description>
109 </method>
110 <method name="get_tile_animation_total_duration" qualifiers="const">
111 <return type="float" />
112 <param index="0" name="atlas_coords" type="Vector2i" />
113 <description>
114 Returns the sum of the sum of the frame durations of the tile at coordinates [param atlas_coords]. This value needs to be divided by the animation speed to get the actual animation loop duration.
115 </description>
116 </method>
117 <method name="get_tile_at_coords" qualifiers="const">
118 <return type="Vector2i" />
119 <param index="0" name="atlas_coords" type="Vector2i" />
120 <description>
121 If there is a tile covering the [param atlas_coords] coordinates, returns the top-left coordinates of the tile (thus its coordinate ID). Returns [code]Vector2i(-1, -1)[/code] otherwise.
122 </description>
123 </method>
124 <method name="get_tile_data" qualifiers="const">
125 <return type="TileData" />
126 <param index="0" name="atlas_coords" type="Vector2i" />
127 <param index="1" name="alternative_tile" type="int" />
128 <description>
129 Returns the [TileData] object for the given atlas coordinates and alternative ID.
130 </description>
131 </method>
132 <method name="get_tile_size_in_atlas" qualifiers="const">
133 <return type="Vector2i" />
134 <param index="0" name="atlas_coords" type="Vector2i" />
135 <description>
136 Returns the size of the tile (in the grid coordinates system) at coordinates [param atlas_coords].
137 </description>
138 </method>
139 <method name="get_tile_texture_region" qualifiers="const">
140 <return type="Rect2i" />
141 <param index="0" name="atlas_coords" type="Vector2i" />
142 <param index="1" name="frame" type="int" default="0" />
143 <description>
144 Returns a tile's texture region in the atlas texture. For animated tiles, a [param frame] argument might be provided for the different frames of the animation.
145 </description>
146 </method>
147 <method name="get_tiles_to_be_removed_on_change">
148 <return type="PackedVector2Array" />
149 <param index="0" name="texture" type="Texture2D" />
150 <param index="1" name="margins" type="Vector2i" />
151 <param index="2" name="separation" type="Vector2i" />
152 <param index="3" name="texture_region_size" type="Vector2i" />
153 <description>
154 Returns an array of tiles coordinates ID that will be automatically removed when modifying one or several of those properties: [param texture], [param margins], [param separation] or [param texture_region_size]. This can be used to undo changes that would have caused tiles data loss.
155 </description>
156 </method>
157 <method name="has_room_for_tile" qualifiers="const">
158 <return type="bool" />
159 <param index="0" name="atlas_coords" type="Vector2i" />
160 <param index="1" name="size" type="Vector2i" />
161 <param index="2" name="animation_columns" type="int" />
162 <param index="3" name="animation_separation" type="Vector2i" />
163 <param index="4" name="frames_count" type="int" />
164 <param index="5" name="ignored_tile" type="Vector2i" default="Vector2i(-1, -1)" />
165 <description>
166 Returns whether there is enough room in an atlas to create/modify a tile with the given properties. If [param ignored_tile] is provided, act as is the given tile was not present in the atlas. This may be used when you want to modify a tile's properties.
167 </description>
168 </method>
169 <method name="has_tiles_outside_texture" qualifiers="const">
170 <return type="bool" />
171 <description>
172 Checks if the source has any tiles that don't fit the texture area (either partially or completely).
173 </description>
174 </method>
175 <method name="move_tile_in_atlas">
176 <return type="void" />
177 <param index="0" name="atlas_coords" type="Vector2i" />
178 <param index="1" name="new_atlas_coords" type="Vector2i" default="Vector2i(-1, -1)" />
179 <param index="2" name="new_size" type="Vector2i" default="Vector2i(-1, -1)" />
180 <description>
181 Move the tile and its alternatives at the [param atlas_coords] coordinates to the [param new_atlas_coords] coordinates with the [param new_size] size. This functions will fail if a tile is already present in the given area.
182 If [param new_atlas_coords] is [code]Vector2i(-1, -1)[/code], keeps the tile's coordinates. If [param new_size] is [code]Vector2i(-1, -1)[/code], keeps the tile's size.
183 To avoid an error, first check if a move is possible using [method has_room_for_tile].
184 </description>
185 </method>
186 <method name="remove_alternative_tile">
187 <return type="void" />
188 <param index="0" name="atlas_coords" type="Vector2i" />
189 <param index="1" name="alternative_tile" type="int" />
190 <description>
191 Remove a tile's alternative with alternative ID [param alternative_tile].
192 Calling this function with [param alternative_tile] equals to 0 will fail, as the base tile alternative cannot be removed.
193 </description>
194 </method>
195 <method name="remove_tile">
196 <return type="void" />
197 <param index="0" name="atlas_coords" type="Vector2i" />
198 <description>
199 Remove a tile and its alternative at coordinates [param atlas_coords].
200 </description>
201 </method>
202 <method name="set_alternative_tile_id">
203 <return type="void" />
204 <param index="0" name="atlas_coords" type="Vector2i" />
205 <param index="1" name="alternative_tile" type="int" />
206 <param index="2" name="new_id" type="int" />
207 <description>
208 Change a tile's alternative ID from [param alternative_tile] to [param new_id].
209 Calling this function with [param new_id] of 0 will fail, as the base tile alternative cannot be moved.
210 </description>
211 </method>
212 <method name="set_tile_animation_columns">
213 <return type="void" />
214 <param index="0" name="atlas_coords" type="Vector2i" />
215 <param index="1" name="frame_columns" type="int" />
216 <description>
217 Sets the number of columns in the animation layout of the tile at coordinates [param atlas_coords]. If set to 0, then the different frames of the animation are laid out as a single horizontal line in the atlas.
218 </description>
219 </method>
220 <method name="set_tile_animation_frame_duration">
221 <return type="void" />
222 <param index="0" name="atlas_coords" type="Vector2i" />
223 <param index="1" name="frame_index" type="int" />
224 <param index="2" name="duration" type="float" />
225 <description>
226 Sets the animation frame [param duration] of frame [param frame_index] for the tile at coordinates [param atlas_coords].
227 </description>
228 </method>
229 <method name="set_tile_animation_frames_count">
230 <return type="void" />
231 <param index="0" name="atlas_coords" type="Vector2i" />
232 <param index="1" name="frames_count" type="int" />
233 <description>
234 Sets how many animation frames the tile at coordinates [param atlas_coords] has.
235 </description>
236 </method>
237 <method name="set_tile_animation_mode">
238 <return type="void" />
239 <param index="0" name="atlas_coords" type="Vector2i" />
240 <param index="1" name="mode" type="int" enum="TileSetAtlasSource.TileAnimationMode" />
241 <description>
242 Sets the tile animation mode of the tile at [param atlas_coords] to [param mode]. See also [method get_tile_animation_mode].
243 </description>
244 </method>
245 <method name="set_tile_animation_separation">
246 <return type="void" />
247 <param index="0" name="atlas_coords" type="Vector2i" />
248 <param index="1" name="separation" type="Vector2i" />
249 <description>
250 Sets the margin (in grid tiles) between each tile in the animation layout of the tile at coordinates [param atlas_coords] has.
251 </description>
252 </method>
253 <method name="set_tile_animation_speed">
254 <return type="void" />
255 <param index="0" name="atlas_coords" type="Vector2i" />
256 <param index="1" name="speed" type="float" />
257 <description>
258 Sets the animation speed of the tile at coordinates [param atlas_coords] has.
259 </description>
260 </method>
261 </methods>
262 <members>
263 <member name="margins" type="Vector2i" setter="set_margins" getter="get_margins" default="Vector2i(0, 0)">
264 Margins, in pixels, to offset the origin of the grid in the texture.
265 </member>
266 <member name="separation" type="Vector2i" setter="set_separation" getter="get_separation" default="Vector2i(0, 0)">
267 Separation, in pixels, between each tile texture region of the grid.
268 </member>
269 <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
270 The atlas texture.
271 </member>
272 <member name="texture_region_size" type="Vector2i" setter="set_texture_region_size" getter="get_texture_region_size" default="Vector2i(16, 16)">
273 The base tile size in the texture (in pixel). This size must be bigger than or equal to the TileSet's [code]tile_size[/code] value.
274 </member>
275 <member name="use_texture_padding" type="bool" setter="set_use_texture_padding" getter="get_use_texture_padding" default="true">
276 If [code]true[/code], generates an internal texture with an additional one pixel padding around each tile. Texture padding avoids a common artifact where lines appear between tiles.
277 Disabling this setting might lead a small performance improvement, as generating the internal texture requires both memory and processing time when the TileSetAtlasSource resource is modified.
278 </member>
279 </members>
280 <constants>
281 <constant name="TILE_ANIMATION_MODE_DEFAULT" value="0" enum="TileAnimationMode">
282 Tile animations start at same time, looking identical.
283 </constant>
284 <constant name="TILE_ANIMATION_MODE_RANDOM_START_TIMES" value="1" enum="TileAnimationMode">
285 Tile animations start at random times, looking varied.
286 </constant>
287 <constant name="TILE_ANIMATION_MODE_MAX" value="2" enum="TileAnimationMode">
288 Represents the size of the [enum TileAnimationMode] enum.
289 </constant>
290 <constant name="TRANSFORM_FLIP_H" value="4096">
291 Represents cell's horizontal flip flag. Should be used directly with [TileMapLayer] to flip placed tiles by altering their alternative IDs.
292 [codeblock]
293 var alternate_id = $TileMapLayer.get_cell_alternative_tile(Vector2i(2, 2))
294 if not alternate_id &amp; TileSetAtlasSource.TRANSFORM_FLIP_H:
295 # If tile is not already flipped, flip it.
296 $TileMapLayer.set_cell(Vector2i(2, 2), source_id, atlas_coords, alternate_id | TileSetAtlasSource.TRANSFORM_FLIP_H)
297 [/codeblock]
298 [b]Note:[/b] These transformations can be combined to do the equivalent of 0, 90, 180, and 270 degree rotations, as shown below:
299 [codeblock]
300 enum TileTransform {
301 ROTATE_0 = 0,
302 ROTATE_90 = TileSetAtlasSource.TRANSFORM_TRANSPOSE | TileSetAtlasSource.TRANSFORM_FLIP_H,
303 ROTATE_180 = TileSetAtlasSource.TRANSFORM_FLIP_H | TileSetAtlasSource.TRANSFORM_FLIP_V,
304 ROTATE_270 = TileSetAtlasSource.TRANSFORM_TRANSPOSE | TileSetAtlasSource.TRANSFORM_FLIP_V,
305 }
306 [/codeblock]
307 </constant>
308 <constant name="TRANSFORM_FLIP_V" value="8192">
309 Represents cell's vertical flip flag. See [constant TRANSFORM_FLIP_H] for usage.
310 </constant>
311 <constant name="TRANSFORM_TRANSPOSE" value="16384">
312 Represents cell's transposed flag. See [constant TRANSFORM_FLIP_H] for usage.
313 </constant>
314 </constants>
315 </class>