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
TransformFlipV
Represents cell's vertical flip flag. See TransformFlipH for usage.
public const long TransformFlipV = 8192
Field Value
TransformTranspose
Represents cell's transposed flag. See TransformFlipH for usage.
public const long TransformTranspose = 16384
Field Value
Properties
Margins
Margins, in pixels, to offset the origin of the grid in the texture.
public Vector2I Margins { get; set; }
Property Value
Separation
Separation, in pixels, between each tile texture region of the grid.
public Vector2I Separation { get; set; }
Property Value
Texture
The atlas texture.
public Texture2D Texture { get; set; }
Property Value
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
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
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
Returns
CreateTile(Vector2I, Vector2I?)
Creates a new tile at coordinates atlasCoords
with the given size
.
public void CreateTile(Vector2I atlasCoords, Vector2I? size = null)
Parameters
atlasCoords
Vector2Isize
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
GetNextAlternativeTileId(Vector2I)
Returns the alternative ID a following call to CreateAlternativeTile(Vector2I, int) would return.
public int GetNextAlternativeTileId(Vector2I atlasCoords)
Parameters
atlasCoords
Vector2I
Returns
GetRuntimeTexture()
If UseTexturePadding is false
, returns Texture. Otherwise, returns and internal ImageTexture created that includes the padding.
public Texture2D GetRuntimeTexture()
Returns
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
Returns
GetTileAnimationColumns(Vector2I)
Returns how many columns the tile at atlasCoords
has in its animation layout.
public int GetTileAnimationColumns(Vector2I atlasCoords)
Parameters
atlasCoords
Vector2I
Returns
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
Returns
GetTileAnimationFramesCount(Vector2I)
Returns how many animation frames has the tile at coordinates atlasCoords
.
public int GetTileAnimationFramesCount(Vector2I atlasCoords)
Parameters
atlasCoords
Vector2I
Returns
GetTileAnimationMode(Vector2I)
Returns the TileSetAtlasSource.TileAnimationMode of the tile at atlasCoords
. See also SetTileAnimationMode(Vector2I, TileAnimationMode).
public TileSetAtlasSource.TileAnimationMode GetTileAnimationMode(Vector2I atlasCoords)
Parameters
atlasCoords
Vector2I
Returns
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
GetTileAnimationSpeed(Vector2I)
Returns the animation speed of the tile at coordinates atlasCoords
.
public float GetTileAnimationSpeed(Vector2I atlasCoords)
Parameters
atlasCoords
Vector2I
Returns
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
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
GetTileData(Vector2I, int)
Returns the TileData object for the given atlas coordinates and alternative ID.
public TileData GetTileData(Vector2I atlasCoords, int alternativeTile)
Parameters
Returns
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
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
Returns
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
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
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
Vector2Isize
Vector2IanimationColumns
intanimationSeparation
Vector2IframesCount
intignoredTile
Vector2I?If the parameter is null, then the default value is
new Vector2I(-1, -1)
.
Returns
HasTilesOutsideTexture()
Checks if the source has any tiles that don't fit the texture area (either partially or completely).
public bool HasTilesOutsideTexture()
Returns
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
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
Vector2InewAtlasCoords
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
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
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
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
SetTileAnimationFramesCount(Vector2I, int)
Sets how many animation frames the tile at coordinates atlasCoords
has.
public void SetTileAnimationFramesCount(Vector2I atlasCoords, int framesCount)
Parameters
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
Vector2Imode
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
SetTileAnimationSpeed(Vector2I, float)
Sets the animation speed of the tile at coordinates atlasCoords
has.
public void SetTileAnimationSpeed(Vector2I atlasCoords, float speed)