Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

TileSetAtlasSource

Inherits: TileSetSource < Resource < RefCounted < Object

Exposes a 2D atlas texture as a set of tiles for a TileSet resource.

Description

An atlas is a grid of tiles laid out on a texture. Each tile in the grid must be exposed using 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 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 get_tile_data.

As TileData properties are stored directly in the TileSetAtlasSource resource, their properties might also be set using TileSetAtlasSource.set("<coords_x>:<coords_y>/<alternative_id>/<tile_data_property>").

Properties

Vector2i

margins

Vector2i(0, 0)

Vector2i

separation

Vector2i(0, 0)

Texture2D

texture

Vector2i

texture_region_size

Vector2i(16, 16)

bool

use_texture_padding

true

Methods

void

clear_tiles_outside_texture ( )

int

create_alternative_tile ( Vector2i atlas_coords, int alternative_id_override=-1 )

void

create_tile ( Vector2i atlas_coords, Vector2i size=Vector2i(1, 1) )

Vector2i

get_atlas_grid_size ( ) const

int

get_next_alternative_tile_id ( Vector2i atlas_coords ) const

Texture2D

get_runtime_texture ( ) const

Rect2i

get_runtime_tile_texture_region ( Vector2i atlas_coords, int frame ) const

int

get_tile_animation_columns ( Vector2i atlas_coords ) const

float

get_tile_animation_frame_duration ( Vector2i atlas_coords, int frame_index ) const

int

get_tile_animation_frames_count ( Vector2i atlas_coords ) const

TileAnimationMode

get_tile_animation_mode ( Vector2i atlas_coords ) const

Vector2i

get_tile_animation_separation ( Vector2i atlas_coords ) const

float

get_tile_animation_speed ( Vector2i atlas_coords ) const

float

get_tile_animation_total_duration ( Vector2i atlas_coords ) const

Vector2i

get_tile_at_coords ( Vector2i atlas_coords ) const

TileData

get_tile_data ( Vector2i atlas_coords, int alternative_tile ) const

Vector2i

get_tile_size_in_atlas ( Vector2i atlas_coords ) const

Rect2i

get_tile_texture_region ( Vector2i atlas_coords, int frame=0 ) const

PackedVector2Array

get_tiles_to_be_removed_on_change ( Texture2D texture, Vector2i margins, Vector2i separation, Vector2i texture_region_size )

bool

has_room_for_tile ( Vector2i atlas_coords, Vector2i size, int animation_columns, Vector2i animation_separation, int frames_count, Vector2i ignored_tile=Vector2i(-1, -1) ) const

bool

has_tiles_outside_texture ( ) const

void

move_tile_in_atlas ( Vector2i atlas_coords, Vector2i new_atlas_coords=Vector2i(-1, -1), Vector2i new_size=Vector2i(-1, -1) )

void

remove_alternative_tile ( Vector2i atlas_coords, int alternative_tile )

void

remove_tile ( Vector2i atlas_coords )

void

set_alternative_tile_id ( Vector2i atlas_coords, int alternative_tile, int new_id )

void

set_tile_animation_columns ( Vector2i atlas_coords, int frame_columns )

void

set_tile_animation_frame_duration ( Vector2i atlas_coords, int frame_index, float duration )

void

set_tile_animation_frames_count ( Vector2i atlas_coords, int frames_count )

void

set_tile_animation_mode ( Vector2i atlas_coords, TileAnimationMode mode )

void

set_tile_animation_separation ( Vector2i atlas_coords, Vector2i separation )

void

set_tile_animation_speed ( Vector2i atlas_coords, float speed )


Enumerations

enum TileAnimationMode:

TileAnimationMode TILE_ANIMATION_MODE_DEFAULT = 0

Tile animations start at same time, looking identical.

TileAnimationMode TILE_ANIMATION_MODE_RANDOM_START_TIMES = 1

Tile animations start at random times, looking varied.

TileAnimationMode TILE_ANIMATION_MODE_MAX = 2

Represents the size of the TileAnimationMode enum.


Constants

TRANSFORM_FLIP_H = 4096

Represents cell's horizontal flip flag. Should be used directly with TileMap to flip placed tiles by altering their alternative IDs.

var alternate_id = $TileMap.get_cell_alternative_tile(0, Vector2i(2, 2))
if not alternate_id & TileSetAtlasSource.TRANSFORM_FLIP_H:
    # If tile is not already flipped, flip it.
    $TileMap.set_cell(0, Vector2i(2, 2), source_id, atlas_coords, alternate_id | TileSetAtlasSource.TRANSFORM_FLIP_H)

TRANSFORM_FLIP_V = 8192

Represents cell's vertical flip flag. See TRANSFORM_FLIP_H for usage.

TRANSFORM_TRANSPOSE = 16384

Represents cell's transposed flag. See TRANSFORM_FLIP_H for usage.


Property Descriptions