reckfellENGINE

TileSetAtlasSource

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

On this page
class TileSetAtlasSourceReckfellSharpInherits TileSetSource

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
# TileSetAtlasSource
C#
public TileSetAtlasSource();

Properties5

MarginsProperty
# Margins
C#
public Vector2I Margins { get; set; }

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

SeparationProperty
# Separation
C#
public Vector2I Separation { get; set; }

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

TextureProperty
# Texture
C#
public Texture2D Texture { get; set; }

The atlas texture.

TextureRegionSizeProperty
# TextureRegionSize
C#
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
# UseTexturePadding
C#
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
# ClearTilesOutsideTexture
C#
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
# CreateAlternativeTile
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
alternativeIdOverrideint-1
Returns int
CreateTilevoid
# CreateTile
C#
public void CreateTile(Vector2I atlasCoords, Vector2I? size = default);

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

Parameters
NameTypeDefault
atlasCoordsVector2I—
sizeVector2I?default
size

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

GetAtlasGridSizeVector2I
# GetAtlasGridSize
C#
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.

Returns Vector2I
GetMarginsVector2I
# GetMargins
C#
public Vector2I GetMargins();
Returns Vector2I
GetNextAlternativeTileIdint
# GetNextAlternativeTileId
C#
public int GetNextAlternativeTileId(Vector2I atlasCoords);

Returns the alternative ID a following call to TileSetAtlasSource.CreateAlternativeTile would return.

Parameters
NameTypeDefault
atlasCoordsVector2I—
Returns int
GetRuntimeTextureTexture2D
# GetRuntimeTexture
C#
public Texture2D GetRuntimeTexture();

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

Returns Texture2D
GetRuntimeTileTextureRegionRect2I
# GetRuntimeTileTextureRegion
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
frameint—
Returns Rect2I
GetSeparationVector2I
# GetSeparation
C#
public Vector2I GetSeparation();
Returns Vector2I
GetTextureTexture2D
# GetTexture
C#
public Texture2D GetTexture();
Returns Texture2D
GetTextureRegionSizeVector2I
# GetTextureRegionSize
C#
public Vector2I GetTextureRegionSize();
Returns Vector2I
GetTileAnimationColumnsint
# GetTileAnimationColumns
C#
public int GetTileAnimationColumns(Vector2I atlasCoords);

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

Parameters
NameTypeDefault
atlasCoordsVector2I—
Returns int
GetTileAnimationFrameDurationfloat
# GetTileAnimationFrameDuration
C#
public float GetTileAnimationFrameDuration(Vector2I atlasCoords, int frameIndex);

Returns the animation frame duration of frame frame_index for the tile at coordinates atlas_coords.

Parameters
NameTypeDefault
atlasCoordsVector2I—
frameIndexint—
Returns float
GetTileAnimationFramesCountint
# GetTileAnimationFramesCount
C#
public int GetTileAnimationFramesCount(Vector2I atlasCoords);

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

Parameters
NameTypeDefault
atlasCoordsVector2I—
Returns int
GetTileAnimationModeTileSetAtlasSource.TileAnimationMode
# GetTileAnimationMode
C#
public TileSetAtlasSource.TileAnimationMode GetTileAnimationMode(Vector2I atlasCoords);

Returns the tile animation mode of the tile at atlas_coords. See also TileSetAtlasSource.SetTileAnimationMode.

Parameters
NameTypeDefault
atlasCoordsVector2I—
Returns TileSetAtlasSource.TileAnimationMode
GetTileAnimationSeparationVector2I
# GetTileAnimationSeparation
C#
public Vector2I GetTileAnimationSeparation(Vector2I atlasCoords);

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

Parameters
NameTypeDefault
atlasCoordsVector2I—
Returns Vector2I
GetTileAnimationSpeedfloat
# GetTileAnimationSpeed
C#
public float GetTileAnimationSpeed(Vector2I atlasCoords);

Returns the animation speed of the tile at coordinates atlas_coords.

Parameters
NameTypeDefault
atlasCoordsVector2I—
Returns float
GetTileAnimationTotalDurationfloat
# GetTileAnimationTotalDuration
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
Returns float
GetTileAtCoordsVector2I
# GetTileAtCoords
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
Returns Vector2I
GetTileDataTileData
# GetTileData
C#
public TileData GetTileData(Vector2I atlasCoords, int alternativeTile);

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

Parameters
NameTypeDefault
atlasCoordsVector2I—
alternativeTileint—
Returns TileData
GetTileSizeInAtlasVector2I
# GetTileSizeInAtlas
C#
public Vector2I GetTileSizeInAtlas(Vector2I atlasCoords);

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

Parameters
NameTypeDefault
atlasCoordsVector2I—
Returns Vector2I
GetTileTextureRegionRect2I
# GetTileTextureRegion
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
frameint0
Returns Rect2I
GetTilesToBeRemovedOnChangeVector2[]
# GetTilesToBeRemovedOnChange
C#
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.

Parameters
NameTypeDefault
textureTexture2D—
marginsVector2I—
separationVector2I—
textureRegionSizeVector2I—
Returns Vector2[]
GetUseTexturePaddingbool
# GetUseTexturePadding
C#
public bool GetUseTexturePadding();
Returns bool
HasRoomForTilebool
# HasRoomForTile
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
sizeVector2I—
animationColumnsint—
animationSeparationVector2I—
framesCountint—
ignoredTileVector2I?default
ignoredTile

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

Returns bool
HasTilesOutsideTexturebool
# HasTilesOutsideTexture
C#
public bool HasTilesOutsideTexture();

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

Returns bool
MoveTileInAtlasvoid
# MoveTileInAtlas
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
newAtlasCoordsVector2I?default
newSizeVector2I?default
newAtlasCoords

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

newSize

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

RemoveAlternativeTilevoid
# RemoveAlternativeTile
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
alternativeTileint—
RemoveTilevoid
# RemoveTile
C#
public void RemoveTile(Vector2I atlasCoords);

Remove a tile and its alternative at coordinates atlas_coords.

Parameters
NameTypeDefault
atlasCoordsVector2I—
SetAlternativeTileIdvoid
# SetAlternativeTileId
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
alternativeTileint—
newIdint—
SetMarginsvoid
# SetMargins
C#
public void SetMargins(Vector2I margins);
Parameters
NameTypeDefault
marginsVector2I—
SetSeparationvoid
# SetSeparation
C#
public void SetSeparation(Vector2I separation);
Parameters
NameTypeDefault
separationVector2I—
SetTexturevoid
# SetTexture
C#
public void SetTexture(Texture2D texture);
Parameters
NameTypeDefault
textureTexture2D—
SetTextureRegionSizevoid
# SetTextureRegionSize
C#
public void SetTextureRegionSize(Vector2I textureRegionSize);
Parameters
NameTypeDefault
textureRegionSizeVector2I—
SetTileAnimationColumnsvoid
# SetTileAnimationColumns
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
frameColumnsint—
SetTileAnimationFrameDurationvoid
# SetTileAnimationFrameDuration
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
frameIndexint—
durationfloat—
SetTileAnimationFramesCountvoid
# SetTileAnimationFramesCount
C#
public void SetTileAnimationFramesCount(Vector2I atlasCoords, int framesCount);

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

Parameters
NameTypeDefault
atlasCoordsVector2I—
framesCountint—
SetTileAnimationModevoid
# SetTileAnimationMode
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
modeTileSetAtlasSource.TileAnimationMode—
SetTileAnimationSeparationvoid
# SetTileAnimationSeparation
C#
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.

Parameters
NameTypeDefault
atlasCoordsVector2I—
separationVector2I—
SetTileAnimationSpeedvoid
# SetTileAnimationSpeed
C#
public void SetTileAnimationSpeed(Vector2I atlasCoords, float speed);

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

Parameters
NameTypeDefault
atlasCoordsVector2I—
speedfloat—
SetUseTexturePaddingvoid
# SetUseTexturePadding
C#
public void SetUseTexturePadding(bool useTexturePadding);
Parameters
NameTypeDefault
useTexturePaddingbool—

Fields and constants3

TransformFlipHField
# TransformFlipH
C#
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:

Text
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
# TransformFlipV
C#
public const long TransformFlipV = 8192;

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

TransformTransposeField
# TransformTranspose
C#
public const long TransformTranspose = 16384;

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

TileSetAtlasSource.TileAnimationMode

ValueDescription
Default = 0

Tile animations start at same time, looking identical.

Max = 2

Represents the size of the TileSetAtlasSource.TileAnimationMode enum.

RandomStartTimes = 1

Tile animations start at random times, looking varied.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.