TileSet

Inherits: Resource < RefCounted < Object

Tile library for tilemaps.

Description

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

Tiles can either be from a TileSetAtlasSource, that render 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 less properties. To do so, the TileSet resources uses property layers, that you can add or remove depending on your needs.

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

See the functions to add new layers for more information.

Tutorials

Properties

TileLayout

tile_layout

0

TileOffsetAxis

tile_offset_axis

0

TileShape

tile_shape

0

Vector2i

tile_size

Vector2i(16, 16)

bool

uv_clipping

false

Methods

void

add_custom_data_layer ( int to_position=-1 )

void

add_navigation_layer ( int to_position=-1 )

void

add_occlusion_layer ( int to_position=-1 )

int

add_pattern ( TileMapPattern pattern, int index=-1 )

void

add_physics_layer ( int to_position=-1 )

int

add_source ( TileSetSource source, int atlas_source_id_override=-1 )

void

add_terrain ( int terrain_set, int to_position=-1 )

void

add_terrain_set ( int to_position=-1 )

void

cleanup_invalid_tile_proxies ( )

void

clear_tile_proxies ( )

Array

get_alternative_level_tile_proxy ( int source_from, Vector2i coords_from, int alternative_from )

Array

get_coords_level_tile_proxy ( int source_from, Vector2i coords_from )

int

get_custom_data_layers_count ( ) const

int

get_navigation_layer_layers ( int layer_index ) const

int

get_navigation_layers_count ( ) const

int

get_next_source_id ( ) const

int

get_occlusion_layer_light_mask ( int layer_index ) const

bool

get_occlusion_layer_sdf_collision ( int layer_index ) const

int

get_occlusion_layers_count ( ) const

TileMapPattern

get_pattern ( int index=-1 )

int

get_patterns_count ( )

int

get_physics_layer_collision_layer ( int layer_index ) const

int

get_physics_layer_collision_mask ( int layer_index ) const

PhysicsMaterial

get_physics_layer_physics_material ( int layer_index ) const

int

get_physics_layers_count ( ) const

TileSetSource

get_source ( int source_id ) const

int

get_source_count ( ) const

int

get_source_id ( int index ) const

int

get_source_level_tile_proxy ( int source_from )

Color

get_terrain_color ( int terrain_set, int terrain_index ) const

String

get_terrain_name ( int terrain_set, int terrain_index ) const

TerrainMode

get_terrain_set_mode ( int terrain_set ) const

int

get_terrain_sets_count ( ) const

int

get_terrains_count ( int terrain_set ) const

bool

has_alternative_level_tile_proxy ( int source_from, Vector2i coords_from, int alternative_from )

bool

has_coords_level_tile_proxy ( int source_from, Vector2i coords_from )

bool

has_source ( int source_id ) const

bool

has_source_level_tile_proxy ( int source_from )

Array

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

void

move_custom_data_layer ( int layer_index, int to_position )

void

move_navigation_layer ( int layer_index, int to_position )

void

move_occlusion_layer ( int layer_index, int to_position )

void

move_physics_layer ( int layer_index, int to_position )

void

move_terrain ( int terrain_set, int terrain_index, int to_position )

void

move_terrain_set ( int terrain_set, int to_position )

void

remove_alternative_level_tile_proxy ( int source_from, Vector2i coords_from, int alternative_from )

void

remove_coords_level_tile_proxy ( int source_from, Vector2i coords_from )

void

remove_custom_data_layer ( int layer_index )

void

remove_navigation_layer ( int layer_index )

void

remove_occlusion_layer ( int layer_index )

void

remove_pattern ( int index )

void

remove_physics_layer ( int layer_index )

void

remove_source ( int source_id )

void

remove_source_level_tile_proxy ( int source_from )

void

remove_terrain ( int terrain_set, int terrain_index )

void

remove_terrain_set ( int terrain_set )

void

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

void

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

void

set_navigation_layer_layers ( int layer_index, int layers )

void

set_occlusion_layer_light_mask ( int layer_index, int light_mask )

void

set_occlusion_layer_sdf_collision ( int layer_index, bool sdf_collision )

void

set_physics_layer_collision_layer ( int layer_index, int layer )

void

set_physics_layer_collision_mask ( int layer_index, int mask )

void

set_physics_layer_physics_material ( int layer_index, PhysicsMaterial physics_material )

void

set_source_id ( int source_id, int new_source_id )

void

set_source_level_tile_proxy ( int source_from, int source_to )

void

set_terrain_color ( int terrain_set, int terrain_index, Color color )

void

set_terrain_name ( int terrain_set, int terrain_index, String name )

void

set_terrain_set_mode ( int terrain_set, TerrainMode mode )

Enumerations

enum TileShape:

  • TILE_SHAPE_SQUARE = 0 --- Rectangular tile shape.

  • TILE_SHAPE_ISOMETRIC = 1 --- Diamond tile shape (for isometric look).

  • TILE_SHAPE_HALF_OFFSET_SQUARE = 2 --- Rectangular tile shape with one row/column out of two offset by half a tile.

  • TILE_SHAPE_HEXAGON = 3 --- Hexagonal tile shape.


enum TileLayout:

  • TILE_LAYOUT_STACKED = 0 --- Tile coordinates layout where both axis stay consistent with their respective local horizontal and vertical axis.

  • TILE_LAYOUT_STACKED_OFFSET = 1 --- Same as TILE_LAYOUT_STAKED, but the first half-offset is negative instead of positive.

  • TILE_LAYOUT_STAIRS_RIGHT = 2 --- Tile coordinates layout where the horizontal axis stay horizontal, and the vertical one goes down-right.

  • TILE_LAYOUT_STAIRS_DOWN = 3 --- Tile coordinates layout where the vertical axis stay vertical, and the horizontal one goes down-right.

  • TILE_LAYOUT_DIAMOND_RIGHT = 4 --- Tile coordinates layout where the horizontal axis goes up-right, and the vertical one goes down-right.

  • TILE_LAYOUT_DIAMOND_DOWN = 5 --- Tile coordinates layout where the horizontal axis goes down-right, and the vertical one goes down-left.


enum TileOffsetAxis:

  • TILE_OFFSET_AXIS_HORIZONTAL = 0 --- Horizontal half-offset.

  • TILE_OFFSET_AXIS_VERTICAL = 1 --- Vertical half-offset.


enum CellNeighbor:

  • CELL_NEIGHBOR_RIGHT_SIDE = 0 --- Neighbor on the right side.

  • CELL_NEIGHBOR_RIGHT_CORNER = 1 --- Neighbor in the right corner.

  • CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE = 2 --- Neighbor on the bottom right side.

  • CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER = 3 --- Neighbor in the bottom right corner.

  • CELL_NEIGHBOR_BOTTOM_SIDE = 4 --- Neighbor on the bottom side.

  • CELL_NEIGHBOR_BOTTOM_CORNER = 5 --- Neighbor in the bottom corner.

  • CELL_NEIGHBOR_BOTTOM_LEFT_SIDE = 6 --- Neighbor on the bottom left side.

  • CELL_NEIGHBOR_BOTTOM_LEFT_CORNER = 7 --- Neighbor in the bottom left corner.

  • CELL_NEIGHBOR_LEFT_SIDE = 8 --- Neighbor on the left side.

  • CELL_NEIGHBOR_LEFT_CORNER = 9 --- Neighbor in the left corner.

  • CELL_NEIGHBOR_TOP_LEFT_SIDE = 10 --- Neighbor on the top left side.

  • CELL_NEIGHBOR_TOP_LEFT_CORNER = 11 --- Neighbor in the top left corner.

  • CELL_NEIGHBOR_TOP_SIDE = 12 --- Neighbor on the top side.

  • CELL_NEIGHBOR_TOP_CORNER = 13 --- Neighbor in the top corner.

  • CELL_NEIGHBOR_TOP_RIGHT_SIDE = 14 --- Neighbor on the top right side.

  • CELL_NEIGHBOR_TOP_RIGHT_CORNER = 15 --- Neighbor in the top right corner.


enum TerrainMode:

  • TERRAIN_MODE_MATCH_CORNERS_AND_SIDES = 0 --- Requires both corners and side to match with neighboring tiles' terrains.

  • TERRAIN_MODE_MATCH_CORNERS = 1 --- Requires corners to match with neighboring tiles' terrains.

  • TERRAIN_MODE_MATCH_SIDES = 2 --- Requires sides to match with neighboring tiles' terrains.

Property Descriptions

Default

0

Setter

set_tile_layout(value)

Getter

get_tile_layout()

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


Default

0

Setter

set_tile_offset_axis(value)

Getter

get_tile_offset_axis()

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


Default

0

Setter

set_tile_shape(value)

Getter

get_tile_shape()

The tile shape.


Default

Vector2i(16, 16)

Setter

set_tile_size(value)

Getter

get_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.


Default

false

Setter

set_uv_clipping(value)

Getter

is_uv_clipping()

Enables/Disable uv clipping when rendering the tiles.

Method Descriptions

  • void add_custom_data_layer ( int to_position=-1 )

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_navigation_layer ( int to_position=-1 )

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_occlusion_layer ( int to_position=-1 )

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.


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


  • void add_physics_layer ( int to_position=-1 )

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.


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 source ID or -1 if the source could not be added.


  • void add_terrain ( int terrain_set, int to_position=-1 )

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_set ( int to_position=-1 )

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 cleanup_invalid_tile_proxies ( )

Clears tile proxies pointing to invalid tiles.


  • void clear_tile_proxies ( )

Clears all tile proxies.


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

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.


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.


  • int get_custom_data_layers_count ( ) const

Returns the custom data layers count.


  • int get_navigation_layer_layers ( int layer_index ) const

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


  • int get_navigation_layers_count ( ) const

Returns the navigation layers count.


  • int get_next_source_id ( ) const

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


  • int get_occlusion_layer_light_mask ( int layer_index ) const

Returns the light mask of the occlusion layer.


  • bool get_occlusion_layer_sdf_collision ( int layer_index ) const

Returns if the occluders from this layer use sdf_collision.


  • int get_occlusion_layers_count ( ) const

Returns the occlusion layers count.


Returns the TileMapPattern at the given index.


  • int get_patterns_count ( )

Returns the number of TileMapPattern this tile set handles.


  • int get_physics_layer_collision_layer ( int layer_index ) 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_mask ( int layer_index ) const

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


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


  • int get_physics_layers_count ( ) const

Returns the physics layers count.


Returns the TileSetSource with ID source_id.


  • int get_source_count ( ) const

Returns the number of TileSetSource in this TileSet.


  • int get_source_id ( int index ) const

Returns the source ID for source with index index.


  • int get_source_level_tile_proxy ( int source_from )

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

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


  • Color get_terrain_color ( int terrain_set, int terrain_index ) const

Returns a terrain's color.


  • String get_terrain_name ( int terrain_set, int terrain_index ) const

Returns a terrain's name.


Returns a terrain set mode.


  • int get_terrain_sets_count ( ) const

Returns the terrain sets count.


  • int get_terrains_count ( int terrain_set ) const

Returns the number of terrains in the given terrain set.


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

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


  • bool has_coords_level_tile_proxy ( int source_from, Vector2i coords_from )

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


  • bool has_source ( int source_id ) const

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


  • bool has_source_level_tile_proxy ( int source_from )

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


According to the configured proxies, maps the provided indentifiers 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.


  • void move_custom_data_layer ( int layer_index, int to_position )

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_navigation_layer ( int layer_index, int to_position )

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_occlusion_layer ( int layer_index, int to_position )

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_physics_layer ( int layer_index, int to_position )

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_terrain ( int terrain_set, int terrain_index, int to_position )

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_set ( int terrain_set, int to_position )

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


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

Removes an alternative-level proxy for the given identifiers.


  • void remove_coords_level_tile_proxy ( int source_from, Vector2i coords_from )

Removes a coordinates-level proxy for the given identifiers.


  • void remove_custom_data_layer ( int layer_index )

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


  • void remove_navigation_layer ( int layer_index )

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


  • void remove_occlusion_layer ( int layer_index )

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


  • void remove_pattern ( int index )

Remove the TileMapPattern at the given index.


  • void remove_physics_layer ( int layer_index )

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


  • void remove_source ( int source_id )

Removes the source with the given source ID.


  • void remove_source_level_tile_proxy ( int source_from )

Removes a source-level tile proxy.


  • void remove_terrain ( int terrain_set, int terrain_index )

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


  • void remove_terrain_set ( int terrain_set )

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


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

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_coords_level_tile_proxy ( int p_source_from, Vector2i coords_from, int source_to, Vector2i coords_to )

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_navigation_layer_layers ( int layer_index, int layers )

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


  • void set_occlusion_layer_light_mask ( int layer_index, int light_mask )

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


  • void set_occlusion_layer_sdf_collision ( int layer_index, bool sdf_collision )

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


  • void set_physics_layer_collision_layer ( int layer_index, int layer )

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


  • void set_physics_layer_collision_mask ( int layer_index, int mask )

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


  • void set_physics_layer_physics_material ( int layer_index, PhysicsMaterial physics_material )

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


  • void set_source_id ( int source_id, int new_source_id )

Changes a source's ID.


  • void set_source_level_tile_proxy ( int source_from, int source_to )

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 atlac 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_terrain_color ( int terrain_set, int terrain_index, Color color )

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


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

Sets a terrain's name.


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