Inheritance #

RefCounted

- AESContext
- AStar2D
- AStar3D
- AStarGrid2D
- AudioEffectInstance (1)
- AudioSample
- AudioSamplePlayback
- AudioStreamPlayback (5)
- CameraFeed
- CharFXTransform
- ConfigFile
- Crypto
- DTLSServer
- DirAccess
- ENetConnection
- EditorContextMenuPlugin
- EditorDebuggerPlugin
- EditorDebuggerSession
- EditorExportPlatform (6)
- EditorExportPlugin
- EditorExportPreset
- EditorFeatureProfile
- EditorFileSystemImportFormatSupportQuery
- EditorInspectorPlugin
- EditorResourceConversionPlugin
- EditorResourcePreviewGenerator
- EditorResourceTooltipPlugin
- EditorSceneFormatImporter (4)
- EditorScenePostImport
- EditorScenePostImportPlugin
- EditorScript
- EditorTranslationParserPlugin
- EncodedObjectAsID
- EngineProfiler
- Expression
- FileAccess
- GLTFObjectModelProperty
- HMACContext
- HTTPClient
- HashingContext
- ImageFormatLoader (1)
- JavaClass
- JavaObject
- JavaScriptObject
- KinematicCollision2D
- KinematicCollision3D
- Lightmapper (1)
- MeshConvexDecompositionSettings
- MeshDataTool
- MultiplayerAPI (2)
- Mutex
- NavigationPathQueryParameters2D
- NavigationPathQueryParameters3D
- NavigationPathQueryResult2D
- NavigationPathQueryResult3D
- Node3DGizmo (1)
- OggPacketSequencePlayback
- OpenXRAPIExtension
- PCKPacker
- PackedDataContainerRef
- PacketPeer (8)
- PhysicsPointQueryParameters2D
- PhysicsPointQueryParameters3D
- PhysicsRayQueryParameters2D
- PhysicsRayQueryParameters3D
- PhysicsShapeQueryParameters2D
- PhysicsShapeQueryParameters3D
- PhysicsTestMotionParameters2D
- PhysicsTestMotionParameters3D
- PhysicsTestMotionResult2D
- PhysicsTestMotionResult3D
- RDAttachmentFormat
- RDFramebufferPass
- RDPipelineColorBlendState
- RDPipelineColorBlendStateAttachment
- RDPipelineDepthStencilState
- RDPipelineMultisampleState
- RDPipelineRasterizationState
- RDPipelineSpecializationConstant
- RDSamplerState
- RDShaderSource
- RDTextureFormat
- RDTextureView
- RDUniform
- RDVertexAttribute
- RandomNumberGenerator
- RegEx
- RegExMatch
- RenderSceneBuffers (2)
- RenderSceneBuffersConfiguration
- Resource (103)
- ResourceFormatLoader
- ResourceFormatSaver
- ResourceImporter (16)
- SceneState
- SceneTreeTimer
- Semaphore
- SkinReference
- StreamPeer (5)
- SurfaceTool
- TCPServer
- TLSOptions
- TextLine
- TextParagraph
- TextServer (1)
- Thread
- TranslationDomain
- TriangleMesh
- Tween
- Tweener (5)
- UDPServer
- UPNP
- UPNPDevice
- WeakRef
- WebRTCPeerConnection (1)
- XMLParser
- XRInterface (4)
- XRPose
- XRTracker (2)
- ZIPPacker
- ZIPReader
Resource

- Animation
- AnimationLibrary
- AnimationNode (6)
- AnimationNodeStateMachinePlayback
- AnimationNodeStateMachineTransition
- AudioBusLayout
- AudioEffect (17)
- AudioStream (10)
- BitMap
- BoneMap
- ButtonGroup
- CameraAttributes (2)
- ColorPalette
- Compositor
- CompositorEffect
- CryptoKey
- Curve
- Curve2D
- Curve3D
- EditorNode3DGizmoPlugin
- EditorSettings
- Environment
- Font (3)
- GDExtension
- GLTFAccessor
- GLTFAnimation
- GLTFBufferView
- GLTFCamera
- GLTFDocument (1)
- GLTFDocumentExtension (1)
- GLTFLight
- GLTFMesh
- GLTFNode
- GLTFPhysicsBody
- GLTFPhysicsShape
- GLTFSkeleton
- GLTFSkin
- GLTFSpecGloss
- GLTFState (1)
- GLTFTexture
- GLTFTextureSampler
- Gradient
- Image
- ImporterMesh
- InputEvent (6)
- JSON
- LabelSettings
- LightmapGIData
- Material (9)
- Mesh (4)
- MeshLibrary
- MissingResource
- MultiMesh
- NavigationMesh
- NavigationMeshSourceGeometryData2D
- NavigationMeshSourceGeometryData3D
- NavigationPolygon
- Noise (1)
- Occluder3D (5)
- OccluderPolygon2D
- OggPacketSequence
- OpenXRAction
- OpenXRActionMap
- OpenXRActionSet
- OpenXRBindingModifier (2)
- OpenXRHapticBase (1)
- OpenXRIPBinding
- OpenXRInteractionProfile
- PackedDataContainer
- PackedScene
- PhysicsMaterial
- PolygonPathFinder
- RDShaderFile
- RDShaderSPIRV
- RichTextEffect
- SceneReplicationConfig
- Script (3)
- Shader (1)
- ShaderInclude
- Shape2D (8)
- Shape3D (9)
- Shortcut
- SkeletonModification2D (7)
- SkeletonModificationStack2D
- SkeletonProfile (1)
- Skin
- Sky
- SpriteFrames
- StyleBox (4)
- SyntaxHighlighter (2)
- Texture (3)
- Theme
- TileMapPattern
- TileSet
- TileSetSource (2)
- Translation (1)
- VideoStream (1)
- VideoStreamPlayback
- VisualShaderNode (62)
- VoxelGIData
- World2D
- World3D
- X509Certificate
TileSetAtlasSource
Table of contents

TileSetAtlasSource #

is_refcounted, is_instantiable, resource, core, not_builtin_classes

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 create_tile. 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 create_alternative_tile, 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 get_tile_data.

As TileData properties are stored directly in the TileSetAtlasSource resource, their properties might also be set using TileSetAtlasSource.set("://").

Members #

var margins: Vector2i = Vector2i(0, 0)#

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

var separation: Vector2i = Vector2i(0, 0)#

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

var texture: Texture2D#

The atlas texture.

var texture_region_size: Vector2i = Vector2i(16, 16)#

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

var use_texture_padding: bool = true#

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.

Methods #

func clear_tiles_outside_texture() -> void#

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 has_tiles_outside_texture beforehand.

func create_alternative_tile(alternative_id_override: int = -1) -> int#

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.

func create_tile(size: Vector2i = Vector2i(1, 1)) -> void#

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

const func get_atlas_grid_size() -> 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 atlas margins, and the tiles' texture_region_size.

const func get_next_alternative_tile_id(atlas_coords: Vector2i) -> int#

Returns the alternative ID a following call to create_alternative_tile would return.

const func get_runtime_texture() -> Texture2D#

If use_texture_padding is false, returns texture. Otherwise, returns and internal ImageTexture created that includes the padding.

const func get_runtime_tile_texture_region(frame: int) -> Rect2i#

Returns the region of the tile at coordinates atlas_coords for the given frame inside the texture returned by get_runtime_texture.

Note: If use_texture_padding is false, returns the same as get_tile_texture_region.

const func get_tile_animation_columns(atlas_coords: Vector2i) -> int#

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

const func get_tile_animation_frame_duration(frame_index: int) -> float#

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

const func get_tile_animation_frames_count(atlas_coords: Vector2i) -> int#

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

const func get_tile_animation_mode(atlas_coords: Vector2i) -> intTileSetAtlasSource.TileAnimationMode#

Returns the tile animation mode of the tile at atlas_coords. See also set_tile_animation_mode.

const func get_tile_animation_separation(atlas_coords: Vector2i) -> Vector2i#

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

const func get_tile_animation_speed(atlas_coords: Vector2i) -> float#

Returns the animation speed of the tile at coordinates atlas_coords.

const func get_tile_animation_total_duration(atlas_coords: Vector2i) -> float#

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.

const func get_tile_at_coords(atlas_coords: Vector2i) -> Vector2i#

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.

const func get_tile_data(alternative_tile: int) -> TileData#

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

const func get_tile_size_in_atlas(atlas_coords: Vector2i) -> Vector2i#

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

const func get_tile_texture_region(frame: int = 0) -> 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 get_tiles_to_be_removed_on_change(texture_region_size: 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 or texture_region_size. This can be used to undo changes that would have caused tiles data loss.

const func has_room_for_tile(ignored_tile: Vector2i = Vector2i(-1, -1)) -> bool#

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.

const func has_tiles_outside_texture() -> bool#

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

func move_tile_in_atlas(new_size: Vector2i = Vector2i(-1, -1)) -> void#

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 has_room_for_tile.

func remove_alternative_tile(alternative_tile: int) -> void#

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.

func remove_tile(atlas_coords: Vector2i) -> void#

Remove a tile and its alternative at coordinates atlas_coords.

func set_alternative_tile_id(new_id: int) -> void#

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.

func set_tile_animation_columns(frame_columns: int) -> void#

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.

func set_tile_animation_frame_duration(duration: float) -> void#

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

func set_tile_animation_frames_count(frames_count: int) -> void#

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

func set_tile_animation_mode(mode: int enumTileSetAtlasSource.TileAnimationMode) -> void#

Sets the tile animation mode of the tile at atlas_coords to mode. See also get_tile_animation_mode.

func set_tile_animation_separation(separation: Vector2i) -> void#

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

func set_tile_animation_speed(speed: float) -> void#

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

Annotations #

Constants #

const TILE_ANIMATION_MODE_DEFAULT = 0 enum TileAnimationMode#

Tile animations start at same time, looking identical.

const TILE_ANIMATION_MODE_RANDOM_START_TIMES = 1 enum TileAnimationMode#

Tile animations start at random times, looking varied.

const TILE_ANIMATION_MODE_MAX = 2 enum TileAnimationMode#

Represents the size of the TileAnimationMode enum.

const TRANSFORM_FLIP_H = 4096#

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)

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,
}

const TRANSFORM_FLIP_V = 8192#

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

const TRANSFORM_TRANSPOSE = 16384#

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

Constructors #

Enums #

TileAnimationMode#

enum TileAnimationMode { TILE_ANIMATION_MODE_DEFAULT = 0, TILE_ANIMATION_MODE_RANDOM_START_TIMES = 1, TILE_ANIMATION_MODE_MAX = 2, }

Notifications#

enum { TRANSFORM_FLIP_H = 4096, TRANSFORM_FLIP_V = 8192, TRANSFORM_TRANSPOSE = 16384, }

Operators #

Signals #

Theme Items #

Tutorials #