TileSetAtlasSource
Exposes a 2D atlas texture as a set of tiles for a TileSet
resource.
class TileSetAtlasSource
An atlas is a grid of tiles laid out on a texture. Each tile in the grid must be exposed using createTile(atlasCoords:size:)
. 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(atlasCoords:alternativeIdOverride:)
, 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(atlasCoords:alternativeTile:)
.
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>")
.
Superclasses
class TileSetSource
Exposes a set of tiles for a
TileSet
resource.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
static let transformFlipH: Int
Represents cell’s horizontal flip flag. Should be used directly with
TileMap
to flip placed tiles by altering their alternative IDs.static let transformFlipV: Int
Represents cell’s vertical flip flag. See
transformFlipH
for usage.static let transformTranspose: Int
Represents cell’s transposed flag. See
transformFlipH
for usage.class var godotClassName: StringName
Instance members
var margins: Vector2i
Margins, in pixels, to offset the origin of the grid in the texture.
var separation: Vector2i
Separation, in pixels, between each tile texture region of the grid.
var texture: Texture2D?
The atlas texture.
var textureRegionSize: Vector2i
The base tile size in the texture (in pixel). This size must be bigger than the TileSet’s
tile_size
value.var useTexturePadding: Bool
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.func 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.func createAlternativeTile(atlasCoords: Vector2i, alternativeIdOverride: Int32
) -> Int32 Creates an alternative tile for the tile at coordinates
atlasCoords
. IfalternativeIdOverride
is -1, give it an automatically generated unique ID, or assigns it the given ID otherwise.func createTile(atlasCoords: Vector2i, size: Vector2i
) Creates a new tile at coordinates
atlasCoords
with the givensize
.func getAtlasGridSize(
) -> Vector2i 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 atlasmargins
, and the tiles’textureRegionSize
.func getNextAlternativeTileId(atlasCoords: Vector2i
) -> Int32 Returns the alternative ID a following call to
createAlternativeTile(atlasCoords:alternativeIdOverride:)
would return.func getRuntimeTexture(
) -> Texture2D? If
useTexturePadding
isfalse
, returnstexture
. Otherwise, returns and internalImageTexture
created that includes the padding.func getRuntimeTileTextureRegion(atlasCoords: Vector2i, frame: Int32
) -> Rect2i Returns the region of the tile at coordinates
atlasCoords
for the givenframe
inside the texture returned bygetRuntimeTexture
.func getTileAnimationColumns(atlasCoords: Vector2i
) -> Int32 Returns how many columns the tile at
atlasCoords
has in its animation layout.func getTileAnimationFrameDuration(atlasCoords: Vector2i, frameIndex: Int32
) -> Double Returns the animation frame duration of frame
frameIndex
for the tile at coordinatesatlasCoords
.func getTileAnimationFramesCount(atlasCoords: Vector2i
) -> Int32 Returns how many animation frames has the tile at coordinates
atlasCoords
.func getTileAnimationMode(atlasCoords: Vector2i
) -> TileSetAtlasSource.TileAnimationMode Returns the tile animation mode of the tile at
atlasCoords
. See alsosetTileAnimationMode(atlasCoords:mode:)
.func getTileAnimationSeparation(atlasCoords: Vector2i
) -> Vector2i Returns the separation (as in the atlas grid) between each frame of an animated tile at coordinates
atlasCoords
.func getTileAnimationSpeed(atlasCoords: Vector2i
) -> Double Returns the animation speed of the tile at coordinates
atlasCoords
.func getTileAnimationTotalDuration(atlasCoords: Vector2i
) -> Double 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.func getTileAtCoords(atlasCoords: Vector2i
) -> Vector2i If there is a tile covering the
atlasCoords
coordinates, returns the top-left coordinates of the tile (thus its coordinate ID). ReturnsVector2i(-1, -1)
otherwise.func getTileData(atlasCoords: Vector2i, alternativeTile: Int32
) -> TileData? Returns the
TileData
object for the given atlas coordinates and alternative ID.func getTileSizeInAtlas(atlasCoords: Vector2i
) -> Vector2i Returns the size of the tile (in the grid coordinates system) at coordinates
atlasCoords
.func getTileTextureRegion(atlasCoords: Vector2i, frame: Int32
) -> Rect2i 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.func getTilesToBeRemovedOnChange(texture: Texture2D?, margins: Vector2i, separation: Vector2i, textureRegionSize: Vector2i
) -> PackedVector2Array Returns an array of tiles coordinates ID that will be automatically removed when modifying one or several of those properties:
texture
,margins
,separation
ortextureRegionSize
. This can be used to undo changes that would have caused tiles data loss.func hasRoomForTile(atlasCoords: Vector2i, size: Vector2i, animationColumns: Int32, animationSeparation: Vector2i, framesCount: Int32, ignoredTile: Vector2i
) -> Bool 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.func hasTilesOutsideTexture(
) -> Bool Checks if the source has any tiles that don’t fit the texture area (either partially or completely).
func moveTileInAtlas(atlasCoords: Vector2i, newAtlasCoords: Vector2i, newSize: Vector2i
) Move the tile and its alternatives at the
atlasCoords
coordinates to thenewAtlasCoords
coordinates with thenewSize
size. This functions will fail if a tile is already present in the given area.func removeAlternativeTile(atlasCoords: Vector2i, alternativeTile: Int32
) Remove a tile’s alternative with alternative ID
alternativeTile
.func removeTile(atlasCoords: Vector2i
) Remove a tile and its alternative at coordinates
atlasCoords
.func setAlternativeTileId(atlasCoords: Vector2i, alternativeTile: Int32, newId: Int32
) Change a tile’s alternative ID from
alternativeTile
tonewId
.func setTileAnimationColumns(atlasCoords: Vector2i, frameColumns: Int32
) 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.func setTileAnimationFrameDuration(atlasCoords: Vector2i, frameIndex: Int32, duration: Double
) Sets the animation frame
duration
of frameframeIndex
for the tile at coordinatesatlasCoords
.func setTileAnimationFramesCount(atlasCoords: Vector2i, framesCount: Int32
) Sets how many animation frames the tile at coordinates
atlasCoords
has.func setTileAnimationMode(atlasCoords: Vector2i, mode: TileSetAtlasSource.TileAnimationMode
) Sets the tile animation mode of the tile at
atlasCoords
tomode
. See alsogetTileAnimationMode(atlasCoords:)
.func setTileAnimationSeparation(atlasCoords: Vector2i, separation: Vector2i
) Sets the margin (in grid tiles) between each tile in the animation layout of the tile at coordinates
atlasCoords
has.func setTileAnimationSpeed(atlasCoords: Vector2i, speed: Double
) Sets the animation speed of the tile at coordinates
atlasCoords
has.