Table of Contents

Class TileSet

Tile library for tilemaps.

Inheritance
TileSet

Remarks

A TileSet is a library of tiles for a TileMapLayer. A TileSet handles a list of TileSetSource, each of them storing a set of tiles.

Tiles can either be from a TileSetAtlasSource, which renders tiles out of a texture with support for physics, navigation, etc., or from a TileSetScenesCollectionSource, which exposes scene-based tiles.

Tiles are referenced by using three IDs: their source ID, their atlas coordinates ID, and their alternative tile ID.

A TileSet can be configured so that its tiles expose more or fewer properties. To do so, the TileSet resources use property layers, which you can add or remove depending on your needs.

For example, adding a physics layer allows giving collision shapes to your tiles. Each layer has dedicated properties (physics layer and mask), so you may add several TileSet physics layers for each type of collision you need.

See the functions to add new layers for more information.

See Also

Properties

tile_layout

For all half-offset shapes (Isometric, Hexagonal and Half-Offset square), changes the way tiles are indexed in the TileMap grid.

var tile_layout : int = 0

Property Value

int

Remarks

  • void set_tile_layout(int value)
  • int get_tile_layout

tile_offset_axis

For all half-offset shapes (Isometric, Hexagonal and Half-Offset square), determines the offset axis.

var tile_offset_axis : int = 0

Property Value

int

Remarks

  • void set_tile_offset_axis(int value)
  • int get_tile_offset_axis

tile_shape

The tile shape.

var tile_shape : int = 0

Property Value

int

Remarks

  • void set_tile_shape(int value)
  • int get_tile_shape

tile_size

The tile size, in pixels. For all tile shapes, this size corresponds to the encompassing rectangle of the tile shape. This is thus the minimal cell size required in an atlas.

var tile_size : Vector2i = Vector2i(16, 16)

Property Value

Vector2i

Remarks

uv_clipping

Enables/Disable uv clipping when rendering the tiles.

var uv_clipping : bool = false

Property Value

bool

Remarks

  • void set_uv_clipping(bool value)
  • bool is_uv_clipping

Methods

add_custom_data_layer(int)

Adds a custom data layer to the TileSet at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

Custom data layers allow assigning custom properties to atlas tiles.

void add_custom_data_layer(int to_position)

Parameters

to_position int

add_navigation_layer(int)

Adds a navigation layer to the TileSet at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

Navigation layers allow assigning a navigable area to atlas tiles.

void add_navigation_layer(int to_position)

Parameters

to_position int

add_occlusion_layer(int)

Adds an occlusion layer to the TileSet at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

Occlusion layers allow assigning occlusion polygons to atlas tiles.

void add_occlusion_layer(int to_position)

Parameters

to_position int

add_pattern(TileMapPattern, int)

Adds a TileMapPattern to be stored in the TileSet resource. If provided, insert it at the given index.

int add_pattern(TileMapPattern pattern, int index)

Parameters

pattern TileMapPattern
index int

add_physics_layer(int)

Adds a physics layer to the TileSet at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

Physics layers allow assigning collision polygons to atlas tiles.

void add_physics_layer(int to_position)

Parameters

to_position int

add_source(TileSetSource, int)

Adds a TileSetSource to the TileSet. If atlas_source_id_override is not -1, also set its source ID. Otherwise, a unique identifier is automatically generated.

The function returns the added source ID or -1 if the source could not be added.

Warning: A source cannot belong to two TileSets at the same time. If the added source was attached to another TileSet, it will be removed from that one.

int add_source(TileSetSource source, int atlas_source_id_override)

Parameters

source TileSetSource
atlas_source_id_override int

add_terrain(int, int)

Adds a new terrain to the given terrain set terrain_set at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

void add_terrain(int terrain_set, int to_position)

Parameters

terrain_set int
to_position int

add_terrain_set(int)

Adds a new terrain set at the given position to_position in the array. If to_position is -1, adds it at the end of the array.

void add_terrain_set(int to_position)

Parameters

to_position int

cleanup_invalid_tile_proxies

Clears tile proxies pointing to invalid tiles.

void cleanup_invalid_tile_proxies

clear_tile_proxies

Clears all tile proxies.

void clear_tile_proxies

get_alternative_level_tile_proxy(int, Vector2i, int)

Returns the alternative-level proxy for the given identifiers. The returned array contains the three proxie's target identifiers (source ID, atlas coords ID and alternative tile ID).

If the TileSet has no proxy for the given identifiers, returns an empty Array.

Array get_alternative_level_tile_proxy(int source_from, Vector2i coords_from, int alternative_from)

Parameters

source_from int
coords_from Vector2i
alternative_from int

get_coords_level_tile_proxy(int, Vector2i)

Returns the coordinate-level proxy for the given identifiers. The returned array contains the two target identifiers of the proxy (source ID and atlas coordinates ID).

If the TileSet has no proxy for the given identifiers, returns an empty Array.

Array get_coords_level_tile_proxy(int source_from, Vector2i coords_from)

Parameters

source_from int
coords_from Vector2i

get_custom_data_layer_by_name(String)

Qualifiers: const

Returns the index of the custom data layer identified by the given name.

int get_custom_data_layer_by_name(String layer_name)

Parameters

layer_name String

get_custom_data_layer_name(int)

Qualifiers: const

Returns the name of the custom data layer identified by the given index.

String get_custom_data_layer_name(int layer_index)

Parameters

layer_index int

get_custom_data_layer_type(int)

Qualifiers: const

Returns the type of the custom data layer identified by the given index.

int get_custom_data_layer_type(int layer_index)

Parameters

layer_index int

get_custom_data_layers_count

Qualifiers: const

Returns the custom data layers count.

int get_custom_data_layers_count

get_navigation_layer_layer_value(int, int)

Qualifiers: const

Returns whether or not the specified navigation layer of the TileSet navigation data layer identified by the given layer_index is enabled, given a navigation_layers layer_number between 1 and 32.

bool get_navigation_layer_layer_value(int layer_index, int layer_number)

Parameters

layer_index int
layer_number int

get_navigation_layer_layers(int)

Qualifiers: const

Returns the navigation layers (as in the Navigation server) of the given TileSet navigation layer.

int get_navigation_layer_layers(int layer_index)

Parameters

layer_index int

get_navigation_layers_count

Qualifiers: const

Returns the navigation layers count.

int get_navigation_layers_count

get_next_source_id

Qualifiers: const

Returns a new unused source ID. This generated ID is the same that a call to TileSet.add_source would return.

int get_next_source_id

get_occlusion_layer_light_mask(int)

Qualifiers: const

Returns the light mask of the occlusion layer.

int get_occlusion_layer_light_mask(int layer_index)

Parameters

layer_index int

get_occlusion_layer_sdf_collision(int)

Qualifiers: const

Returns if the occluders from this layer use sdf_collision.

bool get_occlusion_layer_sdf_collision(int layer_index)

Parameters

layer_index int

get_occlusion_layers_count

Qualifiers: const

Returns the occlusion layers count.

int get_occlusion_layers_count

get_pattern(int)

Returns the TileMapPattern at the given index.

TileMapPattern get_pattern(int index)

Parameters

index int

get_patterns_count

Returns the number of TileMapPattern this tile set handles.

int get_patterns_count

get_physics_layer_collision_layer(int)

Qualifiers: const

Returns the collision layer (as in the physics server) bodies on the given TileSet's physics layer are in.

int get_physics_layer_collision_layer(int layer_index)

Parameters

layer_index int

get_physics_layer_collision_mask(int)

Qualifiers: const

Returns the collision mask of bodies on the given TileSet's physics layer.

int get_physics_layer_collision_mask(int layer_index)

Parameters

layer_index int

get_physics_layer_collision_priority(int)

Qualifiers: const

Returns the collision priority of bodies on the given TileSet's physics layer.

float get_physics_layer_collision_priority(int layer_index)

Parameters

layer_index int

get_physics_layer_physics_material(int)

Qualifiers: const

Returns the physics material of bodies on the given TileSet's physics layer.

PhysicsMaterial get_physics_layer_physics_material(int layer_index)

Parameters

layer_index int

get_physics_layers_count

Qualifiers: const

Returns the physics layers count.

int get_physics_layers_count

get_source(int)

Qualifiers: const

Returns the TileSetSource with ID source_id.

TileSetSource get_source(int source_id)

Parameters

source_id int

get_source_count

Qualifiers: const

Returns the number of TileSetSource in this TileSet.

int get_source_count

get_source_id(int)

Qualifiers: const

Returns the source ID for source with index index.

int get_source_id(int index)

Parameters

index int

get_source_level_tile_proxy(int)

Returns the source-level proxy for the given source identifier.

If the TileSet has no proxy for the given identifier, returns -1.

int get_source_level_tile_proxy(int source_from)

Parameters

source_from int

get_terrain_color(int, int)

Qualifiers: const

Returns a terrain's color.

Color get_terrain_color(int terrain_set, int terrain_index)

Parameters

terrain_set int
terrain_index int

get_terrain_name(int, int)

Qualifiers: const

Returns a terrain's name.

String get_terrain_name(int terrain_set, int terrain_index)

Parameters

terrain_set int
terrain_index int

get_terrain_set_mode(int)

Qualifiers: const

Returns a terrain set mode.

int get_terrain_set_mode(int terrain_set)

Parameters

terrain_set int

get_terrain_sets_count

Qualifiers: const

Returns the terrain sets count.

int get_terrain_sets_count

get_terrains_count(int)

Qualifiers: const

Returns the number of terrains in the given terrain set.

int get_terrains_count(int terrain_set)

Parameters

terrain_set int

has_alternative_level_tile_proxy(int, Vector2i, int)

Returns if there is an alternative-level proxy for the given identifiers.

bool has_alternative_level_tile_proxy(int source_from, Vector2i coords_from, int alternative_from)

Parameters

source_from int
coords_from Vector2i
alternative_from int

has_coords_level_tile_proxy(int, Vector2i)

Returns if there is a coodinates-level proxy for the given identifiers.

bool has_coords_level_tile_proxy(int source_from, Vector2i coords_from)

Parameters

source_from int
coords_from Vector2i

has_custom_data_layer_by_name(String)

Qualifiers: const

Returns if there is a custom data layer named layer_name.

bool has_custom_data_layer_by_name(String layer_name)

Parameters

layer_name String

has_source(int)

Qualifiers: const

Returns if this TileSet has a source for the given source ID.

bool has_source(int source_id)

Parameters

source_id int

has_source_level_tile_proxy(int)

Returns if there is a source-level proxy for the given source ID.

bool has_source_level_tile_proxy(int source_from)

Parameters

source_from int

map_tile_proxy(int, Vector2i, int)

Qualifiers: const

According to the configured proxies, maps the provided identifiers to a new set of identifiers. The source ID, atlas coordinates ID and alternative tile ID are returned as a 3 elements Array.

This function first look for matching alternative-level proxies, then coordinates-level proxies, then source-level proxies.

If no proxy corresponding to provided identifiers are found, returns the same values the ones used as arguments.

Array map_tile_proxy(int source_from, Vector2i coords_from, int alternative_from)

Parameters

source_from int
coords_from Vector2i
alternative_from int

move_custom_data_layer(int, int)

Moves the custom data layer at index layer_index to the given position to_position in the array. Also updates the atlas tiles accordingly.

void move_custom_data_layer(int layer_index, int to_position)

Parameters

layer_index int
to_position int

move_navigation_layer(int, int)

Moves the navigation layer at index layer_index to the given position to_position in the array. Also updates the atlas tiles accordingly.

void move_navigation_layer(int layer_index, int to_position)

Parameters

layer_index int
to_position int

move_occlusion_layer(int, int)

Moves the occlusion layer at index layer_index to the given position to_position in the array. Also updates the atlas tiles accordingly.

void move_occlusion_layer(int layer_index, int to_position)

Parameters

layer_index int
to_position int

move_physics_layer(int, int)

Moves the physics layer at index layer_index to the given position to_position in the array. Also updates the atlas tiles accordingly.

void move_physics_layer(int layer_index, int to_position)

Parameters

layer_index int
to_position int

move_terrain(int, int, int)

Moves the terrain at index terrain_index for terrain set terrain_set to the given position to_position in the array. Also updates the atlas tiles accordingly.

void move_terrain(int terrain_set, int terrain_index, int to_position)

Parameters

terrain_set int
terrain_index int
to_position int

move_terrain_set(int, int)

Moves the terrain set at index terrain_set to the given position to_position in the array. Also updates the atlas tiles accordingly.

void move_terrain_set(int terrain_set, int to_position)

Parameters

terrain_set int
to_position int

remove_alternative_level_tile_proxy(int, Vector2i, int)

Removes an alternative-level proxy for the given identifiers.

void remove_alternative_level_tile_proxy(int source_from, Vector2i coords_from, int alternative_from)

Parameters

source_from int
coords_from Vector2i
alternative_from int

remove_coords_level_tile_proxy(int, Vector2i)

Removes a coordinates-level proxy for the given identifiers.

void remove_coords_level_tile_proxy(int source_from, Vector2i coords_from)

Parameters

source_from int
coords_from Vector2i

remove_custom_data_layer(int)

Removes the custom data layer at index layer_index. Also updates the atlas tiles accordingly.

void remove_custom_data_layer(int layer_index)

Parameters

layer_index int

remove_navigation_layer(int)

Removes the navigation layer at index layer_index. Also updates the atlas tiles accordingly.

void remove_navigation_layer(int layer_index)

Parameters

layer_index int

remove_occlusion_layer(int)

Removes the occlusion layer at index layer_index. Also updates the atlas tiles accordingly.

void remove_occlusion_layer(int layer_index)

Parameters

layer_index int

remove_pattern(int)

Remove the TileMapPattern at the given index.

void remove_pattern(int index)

Parameters

index int

remove_physics_layer(int)

Removes the physics layer at index layer_index. Also updates the atlas tiles accordingly.

void remove_physics_layer(int layer_index)

Parameters

layer_index int

remove_source(int)

Removes the source with the given source ID.

void remove_source(int source_id)

Parameters

source_id int

remove_source_level_tile_proxy(int)

Removes a source-level tile proxy.

void remove_source_level_tile_proxy(int source_from)

Parameters

source_from int

remove_terrain(int, int)

Removes the terrain at index terrain_index in the given terrain set terrain_set. Also updates the atlas tiles accordingly.

void remove_terrain(int terrain_set, int terrain_index)

Parameters

terrain_set int
terrain_index int

remove_terrain_set(int)

Removes the terrain set at index terrain_set. Also updates the atlas tiles accordingly.

void remove_terrain_set(int terrain_set)

Parameters

terrain_set int

set_alternative_level_tile_proxy(int, Vector2i, int, int, Vector2i, int)

Create an alternative-level proxy for the given identifiers. A proxy will map set of tile identifiers to another set of identifiers.

This can be used to replace a tile in all TileMaps using this TileSet, as TileMap nodes will find and use the proxy's target tile when one is available.

Proxied tiles can be automatically replaced in TileMap nodes using the editor.

void set_alternative_level_tile_proxy(int source_from, Vector2i coords_from, int alternative_from, int source_to, Vector2i coords_to, int alternative_to)

Parameters

source_from int
coords_from Vector2i
alternative_from int
source_to int
coords_to Vector2i
alternative_to int

set_coords_level_tile_proxy(int, Vector2i, int, Vector2i)

Creates a coordinates-level proxy for the given identifiers. A proxy will map set of tile identifiers to another set of identifiers. The alternative tile ID is kept the same when using coordinates-level proxies.

This can be used to replace a tile in all TileMaps using this TileSet, as TileMap nodes will find and use the proxy's target tile when one is available.

Proxied tiles can be automatically replaced in TileMap nodes using the editor.

void set_coords_level_tile_proxy(int p_source_from, Vector2i coords_from, int source_to, Vector2i coords_to)

Parameters

p_source_from int
coords_from Vector2i
source_to int
coords_to Vector2i

set_custom_data_layer_name(int, String)

Sets the name of the custom data layer identified by the given index. Names are identifiers of the layer therefore if the name is already taken it will fail and raise an error.

void set_custom_data_layer_name(int layer_index, String layer_name)

Parameters

layer_index int
layer_name String

set_custom_data_layer_type(int, int)

Sets the type of the custom data layer identified by the given index.

void set_custom_data_layer_type(int layer_index, int layer_type)

Parameters

layer_index int
layer_type int

set_navigation_layer_layer_value(int, int, bool)

Based on value, enables or disables the specified navigation layer of the TileSet navigation data layer identified by the given layer_index, given a navigation_layers layer_number between 1 and 32.

void set_navigation_layer_layer_value(int layer_index, int layer_number, bool value)

Parameters

layer_index int
layer_number int
value bool

set_navigation_layer_layers(int, int)

Sets the navigation layers (as in the navigation server) for navigation regions in the given TileSet navigation layer.

void set_navigation_layer_layers(int layer_index, int layers)

Parameters

layer_index int
layers int

set_occlusion_layer_light_mask(int, int)

Sets the occlusion layer (as in the rendering server) for occluders in the given TileSet occlusion layer.

void set_occlusion_layer_light_mask(int layer_index, int light_mask)

Parameters

layer_index int
light_mask int

set_occlusion_layer_sdf_collision(int, bool)

Enables or disables SDF collision for occluders in the given TileSet occlusion layer.

void set_occlusion_layer_sdf_collision(int layer_index, bool sdf_collision)

Parameters

layer_index int
sdf_collision bool

set_physics_layer_collision_layer(int, int)

Sets the collision layer (as in the physics server) for bodies in the given TileSet physics layer.

void set_physics_layer_collision_layer(int layer_index, int layer)

Parameters

layer_index int
layer int

set_physics_layer_collision_mask(int, int)

Sets the collision mask for bodies in the given TileSet physics layer.

void set_physics_layer_collision_mask(int layer_index, int mask)

Parameters

layer_index int
mask int

set_physics_layer_collision_priority(int, float)

Sets the collision priority for bodies in the given TileSet physics layer.

void set_physics_layer_collision_priority(int layer_index, float priority)

Parameters

layer_index int
priority float

set_physics_layer_physics_material(int, PhysicsMaterial)

Sets the physics material for bodies in the given TileSet physics layer.

void set_physics_layer_physics_material(int layer_index, PhysicsMaterial physics_material)

Parameters

layer_index int
physics_material PhysicsMaterial

set_source_id(int, int)

Changes a source's ID.

void set_source_id(int source_id, int new_source_id)

Parameters

source_id int
new_source_id int

set_source_level_tile_proxy(int, int)

Creates a source-level proxy for the given source ID. A proxy will map set of tile identifiers to another set of identifiers. Both the atlas coordinates ID and the alternative tile ID are kept the same when using source-level proxies.

This can be used to replace a source in all TileMaps using this TileSet, as TileMap nodes will find and use the proxy's target source when one is available.

Proxied tiles can be automatically replaced in TileMap nodes using the editor.

void set_source_level_tile_proxy(int source_from, int source_to)

Parameters

source_from int
source_to int

set_terrain_color(int, int, Color)

Sets a terrain's color. This color is used for identifying the different terrains in the TileSet editor.

void set_terrain_color(int terrain_set, int terrain_index, Color color)

Parameters

terrain_set int
terrain_index int
color Color

set_terrain_name(int, int, String)

Sets a terrain's name.

void set_terrain_name(int terrain_set, int terrain_index, String name)

Parameters

terrain_set int
terrain_index int
name String

set_terrain_set_mode(int, int)

Sets a terrain mode. Each mode determines which bits of a tile shape is used to match the neighboring tiles' terrains.

void set_terrain_set_mode(int terrain_set, int mode)

Parameters

terrain_set int
mode int