TileSetAtlasSource
Exposes a 2D atlas texture as a set of tiles for a TileSet resource.
Exposes a 2D atlas texture as a set of tiles for a TileSet resource.
An atlas is a grid of tiles laid out on a texture. Each tile in the grid must be exposed using TileSetAtlasSource.CreateTile. 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 TileSetAtlasSource.CreateAlternativeTile, 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 TileSetAtlasSource.GetTileData.
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>").
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
TileSetAtlasSourceConstructor
public TileSetAtlasSource();Properties5
MarginsProperty
public Vector2I Margins { get; set; }Margins, in pixels, to offset the origin of the grid in the texture.
SeparationProperty
public Vector2I Separation { get; set; }Separation, in pixels, between each tile texture region of the grid.
TextureProperty
public Texture2D Texture { get; set; }The atlas texture.
TextureRegionSizeProperty
public Vector2I TextureRegionSize { get; set; }Base image-region size in atlas pixels. A tile may span several such regions. This does not replace TileSet.TileSize or create collision. CreateTile/SetCell atlas coordinates use atlas-grid units, not these pixel dimensions.
UseTexturePaddingProperty
public bool UseTexturePadding { get; set; }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.
Methods41
ClearTilesOutsideTexturevoid
public void 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 TileSetAtlasSource.HasTilesOutsideTexture beforehand.
CreateAlternativeTileint
public int CreateAlternativeTile(Vector2I atlasCoords, int alternativeIdOverride = -1);Creates an alternative tile for the tile at coordinates atlas_coords. If alternative_id_override 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 alternative_id_override.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
alternativeIdOverride | int | -1 |
intCreateTilevoid
public void CreateTile(Vector2I atlasCoords, Vector2I? size = default);Creates a new tile at coordinates atlas_coords with the given size.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
size | Vector2I? | default |
sizeIf the parameter is null, then the default value is new Vector2I(1, 1).
GetAtlasGridSizeVector2I
public Vector2I GetAtlasGridSize();Returns the atlas grid size, which depends on how many tiles can fit in the texture. It thus depends on the TileSetAtlasSource.Texture's size, the atlas TileSetAtlasSource.Margins, and the tiles' TileSetAtlasSource.TextureRegionSize.
Vector2IGetMarginsVector2I
public Vector2I GetMargins();Vector2IGetNextAlternativeTileIdint
public int GetNextAlternativeTileId(Vector2I atlasCoords);Returns the alternative ID a following call to TileSetAtlasSource.CreateAlternativeTile would return.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
intGetRuntimeTextureTexture2D
public Texture2D GetRuntimeTexture();If TileSetAtlasSource.UseTexturePadding is false, returns TileSetAtlasSource.Texture. Otherwise, returns an internal ImageTexture created that includes the padding.
Texture2DGetRuntimeTileTextureRegionRect2I
public Rect2I GetRuntimeTileTextureRegion(Vector2I atlasCoords, int frame);Returns the region of the tile at coordinates atlas_coords for the given frame inside the texture returned by TileSetAtlasSource.GetRuntimeTexture.
Note: If TileSetAtlasSource.UseTexturePadding is false, returns the same as TileSetAtlasSource.GetTileTextureRegion.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
frame | int | — |
Rect2IGetSeparationVector2I
public Vector2I GetSeparation();Vector2IGetTextureTexture2D
public Texture2D GetTexture();Texture2DGetTextureRegionSizeVector2I
public Vector2I GetTextureRegionSize();Vector2IGetTileAnimationColumnsint
public int GetTileAnimationColumns(Vector2I atlasCoords);Returns how many columns the tile at atlas_coords has in its animation layout.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
intGetTileAnimationFrameDurationfloat
public float GetTileAnimationFrameDuration(Vector2I atlasCoords, int frameIndex);Returns the animation frame duration of frame frame_index for the tile at coordinates atlas_coords.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
frameIndex | int | — |
floatGetTileAnimationFramesCountint
public int GetTileAnimationFramesCount(Vector2I atlasCoords);Returns how many animation frames has the tile at coordinates atlas_coords.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
intGetTileAnimationModeTileSetAtlasSource.TileAnimationMode
public TileSetAtlasSource.TileAnimationMode GetTileAnimationMode(Vector2I atlasCoords);Returns the tile animation mode of the tile at atlas_coords. See also TileSetAtlasSource.SetTileAnimationMode.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
TileSetAtlasSource.TileAnimationModeGetTileAnimationSeparationVector2I
public Vector2I GetTileAnimationSeparation(Vector2I atlasCoords);Returns the separation (as in the atlas grid) between each frame of an animated tile at coordinates atlas_coords.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
Vector2IGetTileAnimationSpeedfloat
public float GetTileAnimationSpeed(Vector2I atlasCoords);Returns the animation speed of the tile at coordinates atlas_coords.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
floatGetTileAnimationTotalDurationfloat
public float GetTileAnimationTotalDuration(Vector2I atlasCoords);Returns the sum of the sum of the frame durations of the tile at coordinates atlas_coords. This value needs to be divided by the animation speed to get the actual animation loop duration.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
floatGetTileAtCoordsVector2I
public Vector2I GetTileAtCoords(Vector2I atlasCoords);If there is a tile covering the atlas_coords coordinates, returns the top-left coordinates of the tile (thus its coordinate ID). Returns Vector2i(-1, -1) otherwise.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
Vector2IGetTileDataTileData
public TileData GetTileData(Vector2I atlasCoords, int alternativeTile);Returns the TileData object for the given atlas coordinates and alternative ID.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
alternativeTile | int | — |
TileDataGetTileSizeInAtlasVector2I
public Vector2I GetTileSizeInAtlas(Vector2I atlasCoords);Returns the size of the tile (in the grid coordinates system) at coordinates atlas_coords.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
Vector2IGetTileTextureRegionRect2I
public Rect2I GetTileTextureRegion(Vector2I atlasCoords, int frame = 0);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.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
frame | int | 0 |
Rect2IGetTilesToBeRemovedOnChangeVector2[]
public Vector2[] GetTilesToBeRemovedOnChange(Texture2D texture, Vector2I margins, Vector2I separation, Vector2I textureRegionSize);Returns an array of tiles coordinates ID that will be automatically removed when modifying one or several of those properties: TileSetAtlasSource.Texture, TileSetAtlasSource.Margins, TileSetAtlasSource.Separation or TileSetAtlasSource.TextureRegionSize. This can be used to undo changes that would have caused tiles data loss.
| Name | Type | Default |
|---|---|---|
texture | Texture2D | — |
margins | Vector2I | — |
separation | Vector2I | — |
textureRegionSize | Vector2I | — |
Vector2[]GetUseTexturePaddingbool
public bool GetUseTexturePadding();boolHasRoomForTilebool
public bool HasRoomForTile(Vector2I atlasCoords, Vector2I size, int animationColumns, Vector2I animationSeparation, int framesCount, Vector2I? ignoredTile = default);Returns whether there is enough room in an atlas to create/modify a tile with the given properties. If ignored_tile 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.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
size | Vector2I | — |
animationColumns | int | — |
animationSeparation | Vector2I | — |
framesCount | int | — |
ignoredTile | Vector2I? | default |
ignoredTileIf the parameter is null, then the default value is new Vector2I(-1, -1).
boolHasTilesOutsideTexturebool
public bool HasTilesOutsideTexture();Checks if the source has any tiles that don't fit the texture area (either partially or completely).
boolMoveTileInAtlasvoid
public void MoveTileInAtlas(Vector2I atlasCoords, Vector2I? newAtlasCoords = default, Vector2I? newSize = default);Move the tile and its alternatives at the atlas_coords coordinates to the new_atlas_coords coordinates with the new_size size. This functions will fail if a tile is already present in the given area.
If new_atlas_coords is Vector2i(-1, -1), keeps the tile's coordinates. If new_size is Vector2i(-1, -1), keeps the tile's size.
To avoid an error, first check if a move is possible using TileSetAtlasSource.HasRoomForTile.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
newAtlasCoords | Vector2I? | default |
newSize | Vector2I? | default |
newAtlasCoordsIf the parameter is null, then the default value is new Vector2I(-1, -1).
newSizeIf the parameter is null, then the default value is new Vector2I(-1, -1).
RemoveAlternativeTilevoid
public void RemoveAlternativeTile(Vector2I atlasCoords, int alternativeTile);Remove a tile's alternative with alternative ID alternative_tile.
Calling this function with alternative_tile equals to 0 will fail, as the base tile alternative cannot be removed.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
alternativeTile | int | — |
RemoveTilevoid
public void RemoveTile(Vector2I atlasCoords);Remove a tile and its alternative at coordinates atlas_coords.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
SetAlternativeTileIdvoid
public void SetAlternativeTileId(Vector2I atlasCoords, int alternativeTile, int newId);Change a tile's alternative ID from alternative_tile to new_id.
Calling this function with new_id of 0 will fail, as the base tile alternative cannot be moved.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
alternativeTile | int | — |
newId | int | — |
SetMarginsvoid
public void SetMargins(Vector2I margins);| Name | Type | Default |
|---|---|---|
margins | Vector2I | — |
SetSeparationvoid
public void SetSeparation(Vector2I separation);| Name | Type | Default |
|---|---|---|
separation | Vector2I | — |
SetTexturevoid
public void SetTexture(Texture2D texture);| Name | Type | Default |
|---|---|---|
texture | Texture2D | — |
SetTextureRegionSizevoid
public void SetTextureRegionSize(Vector2I textureRegionSize);| Name | Type | Default |
|---|---|---|
textureRegionSize | Vector2I | — |
SetTileAnimationColumnsvoid
public void SetTileAnimationColumns(Vector2I atlasCoords, int frameColumns);Sets the number of columns in the animation layout of the tile at coordinates atlas_coords. If set to 0, then the different frames of the animation are laid out as a single horizontal line in the atlas.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
frameColumns | int | — |
SetTileAnimationFrameDurationvoid
public void SetTileAnimationFrameDuration(Vector2I atlasCoords, int frameIndex, float duration);Sets the animation frame duration of frame frame_index for the tile at coordinates atlas_coords.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
frameIndex | int | — |
duration | float | — |
SetTileAnimationFramesCountvoid
public void SetTileAnimationFramesCount(Vector2I atlasCoords, int framesCount);Sets how many animation frames the tile at coordinates atlas_coords has.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
framesCount | int | — |
SetTileAnimationModevoid
public void SetTileAnimationMode(Vector2I atlasCoords, TileSetAtlasSource.TileAnimationMode mode);Sets the tile animation mode of the tile at atlas_coords to mode. See also TileSetAtlasSource.GetTileAnimationMode.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
mode | TileSetAtlasSource.TileAnimationMode | — |
SetTileAnimationSeparationvoid
public void SetTileAnimationSeparation(Vector2I atlasCoords, Vector2I separation);Sets the margin (in grid tiles) between each tile in the animation layout of the tile at coordinates atlas_coords has.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
separation | Vector2I | — |
SetTileAnimationSpeedvoid
public void SetTileAnimationSpeed(Vector2I atlasCoords, float speed);Sets the animation speed of the tile at coordinates atlas_coords has.
| Name | Type | Default |
|---|---|---|
atlasCoords | Vector2I | — |
speed | float | — |
SetUseTexturePaddingvoid
public void SetUseTexturePadding(bool useTexturePadding);| Name | Type | Default |
|---|---|---|
useTexturePadding | bool | — |
Fields and constants3
TransformFlipHField
public const long TransformFlipH = 4096;Represents cell's horizontal flip flag. Should be used directly with TileMapLayer to flip placed tiles by altering their alternative IDs.
Note: These transformations can be combined to do the equivalent of 0, 90, 180, and 270 degree rotations, as shown below:
enum TileTransform {
ROTATE_0 = 0,
ROTATE_90 = TileSetAtlasSource.TRANSFORM_TRANSPOSE | TileSetAtlasSource.TRANSFORM_FLIP_H,
ROTATE_180 = TileSetAtlasSource.TRANSFORM_FLIP_H | TileSetAtlasSource.TRANSFORM_FLIP_V,
ROTATE_270 = TileSetAtlasSource.TRANSFORM_TRANSPOSE | TileSetAtlasSource.TRANSFORM_FLIP_V,
}TransformFlipVField
public const long TransformFlipV = 8192;Represents cell's vertical flip flag. See TileSetAtlasSource.TransformFlipH for usage.
TransformTransposeField
public const long TransformTranspose = 16384;Represents cell's transposed flag. See TileSetAtlasSource.TransformFlipH for usage.
TileSetAtlasSource.TileAnimationMode
| Value | Description |
|---|---|
Default = 0 | Tile animations start at same time, looking identical. |
Max = 2 | Represents the size of the |
RandomStartTimes = 1 | Tile animations start at random times, looking varied. |