summaryrefslogtreecommitdiff
path: root/doc/classes/TileSetAtlasSource.xml
blob: 6580c6bd4c0eec443f67271779b0028a327453b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?xml version="1.0" encoding="UTF-8" ?>
<class name="TileSetAtlasSource" inherits="TileSetSource" version="4.0">
	<brief_description>
		Exposes a 2D atlas texture as a set of tiles for a [TileSet] resource.
	</brief_description>
	<description>
		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.
		Each tile can also have a size in the grid coordinates, making it more or less cells in the atlas.

		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.

		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].
		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].
	</description>
	<tutorials>
	</tutorials>
	<methods>
		<method name="create_alternative_tile">
			<return type="int" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="alternative_id_override" type="int" default="-1" />
			<description>
				Creates an alternative tile for the tile at coords [code]atlas_coords[/code]. If [code]alternative_id_override[/code] is -1, give it an automatically generated unique ID, or assigns it the given ID otherwise.
				Returns the new alternative identifier, or -1 if the alternative could not be created with a provided [code]alternative_id_override[/code].
			</description>
		</method>
		<method name="create_tile">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="size" type="Vector2i" default="Vector2i(1, 1)" />
			<description>
				Creates a new tile at coords [code]atlas_coords[/code] with size [code]size[/code].
			</description>
		</method>
		<method name="get_atlas_grid_size" qualifiers="const">
			<return type="Vector2i" />
			<description>
				Returns the atlas grid size, which depends on how many tiles can fit in the texture. It thus depends on the Texture's size, the atlas [code]margins[/code] the tiles' [code]texture_region_size[/code].
			</description>
		</method>
		<method name="get_next_alternative_tile_id" qualifiers="const">
			<return type="int" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<description>
				Returns the alternative ID a following call to [method create_alternative_tile] would return.
			</description>
		</method>
		<method name="get_runtime_texture" qualifiers="const">
			<return type="Texture2D" />
			<description>
				If [member use_texture_padding] is [code]false[/code], returns [member texture]. Otherwise, returns and internal [ImageTexture] created that includes the padding.
			</description>
		</method>
		<method name="get_runtime_tile_texture_region" qualifiers="const">
			<return type="Rect2i" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="frame" type="int" />
			<description>
				Returns the region of the tile at coordinates [code]atlas_coords[/code] for frame [code]frame[/code] inside the texture returned by [method get_runtime_texture].
				[b]Note:[/b] If [member use_texture_padding] is [code]false[/code], returns the same as [method get_tile_texture_region].
			</description>
		</method>
		<method name="get_tile_animation_columns" qualifiers="const">
			<return type="int" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<description>
				Returns how many columns the tile at [code]atlas_coords[/code] has in its animation layout.
			</description>
		</method>
		<method name="get_tile_animation_frame_duration" qualifiers="const">
			<return type="float" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="frame_index" type="int" />
			<description>
				Returns the animation frame duration of frame [code]frame_index[/code] for the tile at coordinates [code]atlas_coords[/code].
			</description>
		</method>
		<method name="get_tile_animation_frames_count" qualifiers="const">
			<return type="int" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<description>
				Returns how many animation frames has the tile at coordinates [code]atlas_coords[/code].
			</description>
		</method>
		<method name="get_tile_animation_separation" qualifiers="const">
			<return type="Vector2i" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<description>
				Returns the separation (as in the atlas grid) between each frame of an animated tile at coordinates [code]atlas_coords[/code].
			</description>
		</method>
		<method name="get_tile_animation_speed" qualifiers="const">
			<return type="float" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<description>
				Returns the animation speed of the tile at coordinates [code]atlas_coords[/code].
			</description>
		</method>
		<method name="get_tile_animation_total_duration" qualifiers="const">
			<return type="float" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<description>
				Returns the sum of the sum of the frame durations of the tile at coordinates [code]atlas_coords[/code]. This value needs to be divided by the animation speed to get the actual animation loop duration.
			</description>
		</method>
		<method name="get_tile_at_coords" qualifiers="const">
			<return type="Vector2i" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<description>
				If there is a tile covering the [code]atlas_coords[/code] coordinates, returns the top-left coordinates of the tile (thus its coordinate ID). Returns [code]Vector2i(-1, -1)[/code] otherwise.
			</description>
		</method>
		<method name="get_tile_data" qualifiers="const">
			<return type="Object" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="alternative_tile" type="int" />
			<description>
				Returns the [TileData] object for the given atlas coordinates and alternative ID.
			</description>
		</method>
		<method name="get_tile_size_in_atlas" qualifiers="const">
			<return type="Vector2i" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<description>
				Returns the size of the tile (in the grid coordinates system) at coordinates [code]atlas_coords[/code].
			</description>
		</method>
		<method name="get_tile_texture_region" qualifiers="const">
			<return type="Rect2i" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="frame" type="int" default="0" />
			<description>
				Returns a tile's texture region in the atlas texture. For animated tiles, a [code]frame[/code] argument might be provided for the different frames of the animation.
			</description>
		</method>
		<method name="get_tiles_to_be_removed_on_change">
			<return type="PackedVector2Array" />
			<argument index="0" name="texture" type="Texture2D" />
			<argument index="1" name="margins" type="Vector2i" />
			<argument index="2" name="separation" type="Vector2i" />
			<argument index="3" name="texture_region_size" type="Vector2i" />
			<description>
				Returns an array of tiles coordinates ID that will be automatically removed when modifying one or several of those properties: [code]texture[/code], [code]margins[/code], [code]separation[/code] or [code]texture_region_size[/code]. This can be used to undo changes that would have caused tiles data loss.
			</description>
		</method>
		<method name="has_room_for_tile" qualifiers="const">
			<return type="bool" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="size" type="Vector2i" />
			<argument index="2" name="animation_columns" type="int" />
			<argument index="3" name="animation_separation" type="Vector2i" />
			<argument index="4" name="frames_count" type="int" />
			<argument index="5" name="ignored_tile" type="Vector2i" default="Vector2i(-1, -1)" />
			<description>
				Returns whether there is enough room in an atlas to create/modify a tile with the given properties. If [code]ignored_tile[/code] 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.
			</description>
		</method>
		<method name="move_tile_in_atlas">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="new_atlas_coords" type="Vector2i" default="Vector2i(-1, -1)" />
			<argument index="2" name="new_size" type="Vector2i" default="Vector2i(-1, -1)" />
			<description>
				Move the tile and its alternatives at the [code]atlas_coords[/code] coordinates to the [code]new_atlas_coords[/code] coordinates with the [code]new_size[/code] size. This functions will fail if a tile is already present in the given area.
				If [code]new_atlas_coords[/code] is [code]Vector2i(-1, -1)[/code], keeps the tile's coordinates. If [code]new_size[/code] is [code]Vector2i(-1, -1)[/code], keeps the tile's size.
				To avoid an error, first check if a move is possible using [method has_room_for_tile].
			</description>
		</method>
		<method name="remove_alternative_tile">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="alternative_tile" type="int" />
			<description>
				Remove a tile's alternative with alternative ID [code]alternative_tile[/code].
				Calling this function with [code]alternative_tile[/code] equals to 0 will fail, as the base tile alternative cannot be removed.
			</description>
		</method>
		<method name="remove_tile">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<description>
				Remove a tile and its alternative at coordinates [code]atlas_coords[/code].
			</description>
		</method>
		<method name="set_alternative_tile_id">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="alternative_tile" type="int" />
			<argument index="2" name="new_id" type="int" />
			<description>
				Change a tile's alternative ID from [code]alternative_tile[/code] to [code]new_id[/code].
				Calling this function with [code]alternative_id[/code] equals to 0 will fail, as the base tile alternative cannot be moved.
			</description>
		</method>
		<method name="set_tile_animation_columns">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="frame_columns" type="int" />
			<description>
				Sets the number of columns in the animation layout of the tile at coordinates [code]atlas_coords[/code]. If set to 0, then the different frames of the animation are laid out as a single horizontal line in the atlas.
			</description>
		</method>
		<method name="set_tile_animation_frame_duration">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="frame_index" type="int" />
			<argument index="2" name="duration" type="float" />
			<description>
				Sets the animation frame duration of frame [code]frame_index[/code] for the tile at coordinates [code]atlas_coords[/code].
			</description>
		</method>
		<method name="set_tile_animation_frames_count">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="frames_count" type="int" />
			<description>
				Sets how many animation frames the tile at coordinates [code]atlas_coords[/code] has.
			</description>
		</method>
		<method name="set_tile_animation_separation">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="separation" type="Vector2i" />
			<description>
				Sets the margin (in grid tiles) between each tile in the animation layout of the tile at coordinates [code]atlas_coords[/code] has.
			</description>
		</method>
		<method name="set_tile_animation_speed">
			<return type="void" />
			<argument index="0" name="atlas_coords" type="Vector2i" />
			<argument index="1" name="speed" type="float" />
			<description>
				Sets the animation speed of the tile at coordinates [code]atlas_coords[/code] has.
			</description>
		</method>
	</methods>
	<members>
		<member name="margins" type="Vector2i" setter="set_margins" getter="get_margins" default="Vector2i(0, 0)">
			Margins, in pixels, to offset the origin of the grid in the texture.
		</member>
		<member name="separation" type="Vector2i" setter="set_separation" getter="get_separation" default="Vector2i(0, 0)">
			Separation, in pixels, between each tile texture region of the grid.
		</member>
		<member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
			The atlas texture.
		</member>
		<member name="texture_region_size" type="Vector2i" setter="set_texture_region_size" getter="get_texture_region_size" default="Vector2i(16, 16)">
			The base tile size in the texture (in pixel). This size must be bigger than the TileSet's [code]tile_size[/code] value.
		</member>
		<member name="use_texture_padding" type="bool" setter="set_use_texture_padding" getter="get_use_texture_padding" default="true">
			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.
			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.
		</member>
	</members>
</class>