Table of Contents

Class TileSetAtlasSource

Namespace
Godot
Assembly
GodotSharp.dll

An atlas is a grid of tiles laid out on a texture. Each tile in the grid must be exposed using CreateTile(Vector2I, Vector2I?). 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 CreateAlternativeTile(Vector2I, int), 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 GetTileData(Vector2I, int).

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>").

public class TileSetAtlasSource : TileSetSource, IDisposable
Inheritance
TileSetAtlasSource
Implements
Inherited Members

Constructors

TileSetAtlasSource()

public TileSetAtlasSource()

Fields

TransformFlipH

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)
public const long TransformFlipH = 4096

Field Value

long

TransformFlipV

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

public const long TransformFlipV = 8192

Field Value

long

TransformTranspose

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

public const long TransformTranspose = 16384

Field Value

long

Properties

Margins

Margins, in pixels, to offset the origin of the grid in the texture.

public Vector2I Margins { get; set; }

Property Value

Vector2I

Separation

Separation, in pixels, between each tile texture region of the grid.

public Vector2I Separation { get; set; }

Property Value

Vector2I

Texture

The atlas texture.

public Texture2D Texture { get; set; }

Property Value

Texture2D

TextureRegionSize

The base tile size in the texture (in pixel). This size must be bigger than the TileSet's tile_size value.

public Vector2I TextureRegionSize { get; set; }

Property Value

Vector2I

UseTexturePadding

If true, 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.

public bool UseTexturePadding { get; set; }

Property Value

bool

Methods

ClearTilesOutsideTexture()

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 HasTilesOutsideTexture() beforehand.

public void ClearTilesOutsideTexture()

CreateAlternativeTile(Vector2I, int)

Creates an alternative tile for the tile at coordinates atlasCoords. If alternativeIdOverride 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 alternativeIdOverride.

public int CreateAlternativeTile(Vector2I atlasCoords, int alternativeIdOverride = -1)

Parameters

atlasCoords Vector2I
alternativeIdOverride int

Returns

int

CreateTile(Vector2I, Vector2I?)

Creates a new tile at coordinates atlasCoords with the given size.

public void CreateTile(Vector2I atlasCoords, Vector2I? size = null)

Parameters

atlasCoords Vector2I
size Vector2I?

If the parameter is null, then the default value is new Vector2I(1, 1).

GetAtlasGridSize()

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 Margins, and the tiles' TextureRegionSize.

public Vector2I GetAtlasGridSize()

Returns

Vector2I

GetNextAlternativeTileId(Vector2I)

Returns the alternative ID a following call to CreateAlternativeTile(Vector2I, int) would return.

public int GetNextAlternativeTileId(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

Returns

int

GetRuntimeTexture()

If UseTexturePadding is false, returns Texture. Otherwise, returns and internal ImageTexture created that includes the padding.

public Texture2D GetRuntimeTexture()

Returns

Texture2D

GetRuntimeTileTextureRegion(Vector2I, int)

Returns the region of the tile at coordinates atlasCoords for the given frame inside the texture returned by GetRuntimeTexture().

Note: If UseTexturePadding is false, returns the same as GetTileTextureRegion(Vector2I, int).

public Rect2I GetRuntimeTileTextureRegion(Vector2I atlasCoords, int frame)

Parameters

atlasCoords Vector2I
frame int

Returns

Rect2I

GetTileAnimationColumns(Vector2I)

Returns how many columns the tile at atlasCoords has in its animation layout.

public int GetTileAnimationColumns(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

Returns

int

GetTileAnimationFrameDuration(Vector2I, int)

Returns the animation frame duration of frame frameIndex for the tile at coordinates atlasCoords.

public float GetTileAnimationFrameDuration(Vector2I atlasCoords, int frameIndex)

Parameters

atlasCoords Vector2I
frameIndex int

Returns

float

GetTileAnimationFramesCount(Vector2I)

Returns how many animation frames has the tile at coordinates atlasCoords.

public int GetTileAnimationFramesCount(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

Returns

int

GetTileAnimationMode(Vector2I)

public TileSetAtlasSource.TileAnimationMode GetTileAnimationMode(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

Returns

TileSetAtlasSource.TileAnimationMode

GetTileAnimationSeparation(Vector2I)

Returns the separation (as in the atlas grid) between each frame of an animated tile at coordinates atlasCoords.

public Vector2I GetTileAnimationSeparation(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

Returns

Vector2I

GetTileAnimationSpeed(Vector2I)

Returns the animation speed of the tile at coordinates atlasCoords.

public float GetTileAnimationSpeed(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

Returns

float

GetTileAnimationTotalDuration(Vector2I)

Returns the sum of the sum of the frame durations of the tile at coordinates atlasCoords. This value needs to be divided by the animation speed to get the actual animation loop duration.

public float GetTileAnimationTotalDuration(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

Returns

float

GetTileAtCoords(Vector2I)

If there is a tile covering the atlasCoords coordinates, returns the top-left coordinates of the tile (thus its coordinate ID). Returns Vector2i(-1, -1) otherwise.

public Vector2I GetTileAtCoords(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

Returns

Vector2I

GetTileData(Vector2I, int)

Returns the TileData object for the given atlas coordinates and alternative ID.

public TileData GetTileData(Vector2I atlasCoords, int alternativeTile)

Parameters

atlasCoords Vector2I
alternativeTile int

Returns

TileData

GetTileSizeInAtlas(Vector2I)

Returns the size of the tile (in the grid coordinates system) at coordinates atlasCoords.

public Vector2I GetTileSizeInAtlas(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

Returns

Vector2I

GetTileTextureRegion(Vector2I, int)

Returns a tile's texture region in the atlas texture. For animated tiles, a frame argument might be provided for the different frames of the animation.

public Rect2I GetTileTextureRegion(Vector2I atlasCoords, int frame = 0)

Parameters

atlasCoords Vector2I
frame int

Returns

Rect2I

GetTilesToBeRemovedOnChange(Texture2D, Vector2I, Vector2I, Vector2I)

Returns an array of tiles coordinates ID that will be automatically removed when modifying one or several of those properties: texture, margins, separation or textureRegionSize. This can be used to undo changes that would have caused tiles data loss.

public Vector2[] GetTilesToBeRemovedOnChange(Texture2D texture, Vector2I margins, Vector2I separation, Vector2I textureRegionSize)

Parameters

texture Texture2D
margins Vector2I
separation Vector2I
textureRegionSize Vector2I

Returns

Vector2[]

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

HasRoomForTile(Vector2I, Vector2I, int, Vector2I, int, Vector2I?)

Returns whether there is enough room in an atlas to create/modify a tile with the given properties. If ignoredTile 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.

public bool HasRoomForTile(Vector2I atlasCoords, Vector2I size, int animationColumns, Vector2I animationSeparation, int framesCount, Vector2I? ignoredTile = null)

Parameters

atlasCoords Vector2I
size Vector2I
animationColumns int
animationSeparation Vector2I
framesCount int
ignoredTile Vector2I?

If the parameter is null, then the default value is new Vector2I(-1, -1).

Returns

bool

HasTilesOutsideTexture()

Checks if the source has any tiles that don't fit the texture area (either partially or completely).

public bool HasTilesOutsideTexture()

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

MoveTileInAtlas(Vector2I, Vector2I?, Vector2I?)

Move the tile and its alternatives at the atlasCoords coordinates to the newAtlasCoords coordinates with the newSize size. This functions will fail if a tile is already present in the given area.

If newAtlasCoords is Vector2i(-1, -1), keeps the tile's coordinates. If newSize is Vector2i(-1, -1), keeps the tile's size.

To avoid an error, first check if a move is possible using HasRoomForTile(Vector2I, Vector2I, int, Vector2I, int, Vector2I?).

public void MoveTileInAtlas(Vector2I atlasCoords, Vector2I? newAtlasCoords = null, Vector2I? newSize = null)

Parameters

atlasCoords Vector2I
newAtlasCoords Vector2I?

If the parameter is null, then the default value is new Vector2I(-1, -1).

newSize Vector2I?

If the parameter is null, then the default value is new Vector2I(-1, -1).

RemoveAlternativeTile(Vector2I, int)

Remove a tile's alternative with alternative ID alternativeTile.

Calling this function with alternativeTile equals to 0 will fail, as the base tile alternative cannot be removed.

public void RemoveAlternativeTile(Vector2I atlasCoords, int alternativeTile)

Parameters

atlasCoords Vector2I
alternativeTile int

RemoveTile(Vector2I)

Remove a tile and its alternative at coordinates atlasCoords.

public void RemoveTile(Vector2I atlasCoords)

Parameters

atlasCoords Vector2I

SetAlternativeTileId(Vector2I, int, int)

Change a tile's alternative ID from alternativeTile to newId.

Calling this function with newId of 0 will fail, as the base tile alternative cannot be moved.

public void SetAlternativeTileId(Vector2I atlasCoords, int alternativeTile, int newId)

Parameters

atlasCoords Vector2I
alternativeTile int
newId int

SetTileAnimationColumns(Vector2I, int)

Sets the number of columns in the animation layout of the tile at coordinates atlasCoords. If set to 0, then the different frames of the animation are laid out as a single horizontal line in the atlas.

public void SetTileAnimationColumns(Vector2I atlasCoords, int frameColumns)

Parameters

atlasCoords Vector2I
frameColumns int

SetTileAnimationFrameDuration(Vector2I, int, float)

Sets the animation frame duration of frame frameIndex for the tile at coordinates atlasCoords.

public void SetTileAnimationFrameDuration(Vector2I atlasCoords, int frameIndex, float duration)

Parameters

atlasCoords Vector2I
frameIndex int
duration float

SetTileAnimationFramesCount(Vector2I, int)

Sets how many animation frames the tile at coordinates atlasCoords has.

public void SetTileAnimationFramesCount(Vector2I atlasCoords, int framesCount)

Parameters

atlasCoords Vector2I
framesCount int

SetTileAnimationMode(Vector2I, TileAnimationMode)

Sets the TileSetAtlasSource.TileAnimationMode of the tile at atlasCoords to mode. See also GetTileAnimationMode(Vector2I).

public void SetTileAnimationMode(Vector2I atlasCoords, TileSetAtlasSource.TileAnimationMode mode)

Parameters

atlasCoords Vector2I
mode TileSetAtlasSource.TileAnimationMode

SetTileAnimationSeparation(Vector2I, Vector2I)

Sets the margin (in grid tiles) between each tile in the animation layout of the tile at coordinates atlasCoords has.

public void SetTileAnimationSeparation(Vector2I atlasCoords, Vector2I separation)

Parameters

atlasCoords Vector2I
separation Vector2I

SetTileAnimationSpeed(Vector2I, float)

Sets the animation speed of the tile at coordinates atlasCoords has.

public void SetTileAnimationSpeed(Vector2I atlasCoords, float speed)

Parameters

atlasCoords Vector2I
speed float