TileSet
Tile library for tilemaps.
TileSet.swift:22class TileSet
A TileSet is a library of tiles for a TileMap
. A TileSet handles a list of TileSetSource
, each of them storing a set of tiles.
Tiles can either be from a TileSetAtlasSource
, which renders tiles out of a texture with support for physics, navigation, etc., or from a TileSetScenesCollectionSource
, which exposes scene-based tiles.
Tiles are referenced by using three IDs: their source ID, their atlas coordinates ID, and their alternative tile ID.
A TileSet can be configured so that its tiles expose more or fewer properties. To do so, the TileSet resources use property layers, which you can add or remove depending on your needs.
For example, adding a physics layer allows giving collision shapes to your tiles. Each layer has dedicated properties (physics layer and mask), so you may add several TileSet physics layers for each type of collision you need.
See the functions to add new layers for more information.
Superclasses
class Resource
Base class for serializable objects.
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
Instance members
var tileLayout: TileSet.TileLayout
For all half-offset shapes (Isometric, Hexagonal and Half-Offset square), changes the way tiles are indexed in the TileMap grid.
var tileOffsetAxis: TileSet.TileOffsetAxis
For all half-offset shapes (Isometric, Hexagonal and Half-Offset square), determines the offset axis.
var tileShape: TileSet.TileShape
The tile shape.
var tileSize: Vector2i
The tile size, in pixels. For all tile shapes, this size corresponds to the encompassing rectangle of the tile shape. This is thus the minimal cell size required in an atlas.
var uvClipping: Bool
Enables/Disable uv clipping when rendering the tiles.
func addCustomDataLayer(toPosition: Int32
) Adds a custom data layer to the TileSet at the given position
toPosition
in the array. IftoPosition
is -1, adds it at the end of the array.func addOcclusionLayer(toPosition: Int32
) Adds an occlusion layer to the TileSet at the given position
toPosition
in the array. IftoPosition
is -1, adds it at the end of the array.func addPattern(TileMapPattern?, index: Int32
) -> Int32 Adds a
TileMapPattern
to be stored in the TileSet resource. If provided, insert it at the givenindex
.func addPhysicsLayer(toPosition: Int32
) Adds a physics layer to the TileSet at the given position
toPosition
in the array. IftoPosition
is -1, adds it at the end of the array.func addSource(TileSetSource?, atlasSourceIdOverride: Int32
) -> Int32 Adds a
TileSetSource
to the TileSet. IfatlasSourceIdOverride
is not -1, also set its source ID. Otherwise, a unique identifier is automatically generated.func addTerrain(terrainSet: Int32, toPosition: Int32
) Adds a new terrain to the given terrain set
terrainSet
at the given positiontoPosition
in the array. IftoPosition
is -1, adds it at the end of the array.func addTerrainSet(toPosition: Int32
) Adds a new terrain set at the given position
toPosition
in the array. IftoPosition
is -1, adds it at the end of the array.func cleanupInvalidTileProxies(
) Clears tile proxies pointing to invalid tiles.
func clearTileProxies(
) Clears all tile proxies.
func getAlternativeLevelTileProxy(sourceFrom: Int32, coordsFrom: Vector2i, alternativeFrom: Int32
) -> GArray Returns the alternative-level proxy for the given identifiers. The returned array contains the three proxie’s target identifiers (source ID, atlas coords ID and alternative tile ID).
func getCoordsLevelTileProxy(sourceFrom: Int32, coordsFrom: Vector2i
) -> GArray Returns the coordinate-level proxy for the given identifiers. The returned array contains the two target identifiers of the proxy (source ID and atlas coordinates ID).
func getCustomDataLayerByName(layerName: String
) -> Int32 Returns the index of the custom data layer identified by the given name.
func getCustomDataLayerName(layerIndex: Int32
) -> String Returns the name of the custom data layer identified by the given index.
func getCustomDataLayerType(layerIndex: Int32
) -> Variant.GType Returns the type of the custom data layer identified by the given index.
func getCustomDataLayersCount(
) -> Int32 Returns the custom data layers count.
func getNextSourceId(
) -> Int32 Returns a new unused source ID. This generated ID is the same that a call to
addSource(_:atlasSourceIdOverride:)
would return.func getOcclusionLayerLightMask(layerIndex: Int32
) -> Int32 Returns the light mask of the occlusion layer.
func getOcclusionLayerSdfCollision(layerIndex: Int32
) -> Bool Returns if the occluders from this layer use
sdf_collision
.func getOcclusionLayersCount(
) -> Int32 Returns the occlusion layers count.
func getPattern(index: Int32
) -> TileMapPattern? Returns the
TileMapPattern
at the givenindex
.func getPatternsCount(
) -> Int32 Returns the number of
TileMapPattern
this tile set handles.func getPhysicsLayerCollisionLayer(layerIndex: Int32
) -> UInt32 Returns the collision layer (as in the physics server) bodies on the given TileSet’s physics layer are in.
func getPhysicsLayerCollisionMask(layerIndex: Int32
) -> UInt32 Returns the collision mask of bodies on the given TileSet’s physics layer.
func getPhysicsLayerPhysicsMaterial(layerIndex: Int32
) -> PhysicsMaterial? Returns the physics material of bodies on the given TileSet’s physics layer.
func getPhysicsLayersCount(
) -> Int32 Returns the physics layers count.
func getSource(sourceId: Int32
) -> TileSetSource? Returns the
TileSetSource
with IDsourceId
.func getSourceCount(
) -> Int32 Returns the number of
TileSetSource
in this TileSet.func getSourceId(index: Int32
) -> Int32 Returns the source ID for source with index
index
.func getSourceLevelTileProxy(sourceFrom: Int32
) -> Int32 Returns the source-level proxy for the given source identifier.
func getTerrainColor(terrainSet: Int32, terrainIndex: Int32
) -> Color Returns a terrain’s color.
func getTerrainName(terrainSet: Int32, terrainIndex: Int32
) -> String Returns a terrain’s name.
func getTerrainSetMode(terrainSet: Int32
) -> TileSet.TerrainMode Returns a terrain set mode.
func getTerrainSetsCount(
) -> Int32 Returns the terrain sets count.
func getTerrainsCount(terrainSet: Int32
) -> Int32 Returns the number of terrains in the given terrain set.
func hasAlternativeLevelTileProxy(sourceFrom: Int32, coordsFrom: Vector2i, alternativeFrom: Int32
) -> Bool Returns if there is an alternative-level proxy for the given identifiers.
func hasCoordsLevelTileProxy(sourceFrom: Int32, coordsFrom: Vector2i
) -> Bool Returns if there is a coodinates-level proxy for the given identifiers.
func hasSource(sourceId: Int32
) -> Bool Returns if this TileSet has a source for the given source ID.
func hasSourceLevelTileProxy(sourceFrom: Int32
) -> Bool Returns if there is a source-level proxy for the given source ID.
func mapTileProxy(sourceFrom: Int32, coordsFrom: Vector2i, alternativeFrom: Int32
) -> GArray According to the configured proxies, maps the provided identifiers to a new set of identifiers. The source ID, atlas coordinates ID and alternative tile ID are returned as a 3 elements Array.
func moveCustomDataLayer(layerIndex: Int32, toPosition: Int32
) Moves the custom data layer at index
layerIndex
to the given positiontoPosition
in the array. Also updates the atlas tiles accordingly.func moveOcclusionLayer(layerIndex: Int32, toPosition: Int32
) Moves the occlusion layer at index
layerIndex
to the given positiontoPosition
in the array. Also updates the atlas tiles accordingly.func movePhysicsLayer(layerIndex: Int32, toPosition: Int32
) Moves the physics layer at index
layerIndex
to the given positiontoPosition
in the array. Also updates the atlas tiles accordingly.func moveTerrain(terrainSet: Int32, terrainIndex: Int32, toPosition: Int32
) Moves the terrain at index
terrainIndex
for terrain setterrainSet
to the given positiontoPosition
in the array. Also updates the atlas tiles accordingly.func moveTerrainSet(Int32, toPosition: Int32
) Moves the terrain set at index
terrainSet
to the given positiontoPosition
in the array. Also updates the atlas tiles accordingly.func removeAlternativeLevelTileProxy(sourceFrom: Int32, coordsFrom: Vector2i, alternativeFrom: Int32
) Removes an alternative-level proxy for the given identifiers.
func removeCoordsLevelTileProxy(sourceFrom: Int32, coordsFrom: Vector2i
) Removes a coordinates-level proxy for the given identifiers.
func removeCustomDataLayer(layerIndex: Int32
) Removes the custom data layer at index
layerIndex
. Also updates the atlas tiles accordingly.func removeOcclusionLayer(layerIndex: Int32
) Removes the occlusion layer at index
layerIndex
. Also updates the atlas tiles accordingly.func removePattern(index: Int32
) Remove the
TileMapPattern
at the given index.func removePhysicsLayer(layerIndex: Int32
) Removes the physics layer at index
layerIndex
. Also updates the atlas tiles accordingly.func removeSource(sourceId: Int32
) Removes the source with the given source ID.
func removeSourceLevelTileProxy(sourceFrom: Int32
) Removes a source-level tile proxy.
func removeTerrain(terrainSet: Int32, terrainIndex: Int32
) Removes the terrain at index
terrainIndex
in the given terrain setterrainSet
. Also updates the atlas tiles accordingly.func removeTerrainSet(Int32
) Removes the terrain set at index
terrainSet
. Also updates the atlas tiles accordingly.func setAlternativeLevelTileProxy(sourceFrom: Int32, coordsFrom: Vector2i, alternativeFrom: Int32, sourceTo: Int32, coordsTo: Vector2i, alternativeTo: Int32
) Create an alternative-level proxy for the given identifiers. A proxy will map set of tile identifiers to another set of identifiers.
func setCoordsLevelTileProxy(pSourceFrom: Int32, coordsFrom: Vector2i, sourceTo: Int32, coordsTo: Vector2i
) Creates a coordinates-level proxy for the given identifiers. A proxy will map set of tile identifiers to another set of identifiers. The alternative tile ID is kept the same when using coordinates-level proxies.
func setCustomDataLayerName(layerIndex: Int32, layerName: String
) Sets the name of the custom data layer identified by the given index. Names are identifiers of the layer therefore if the name is already taken it will fail and raise an error.
func setCustomDataLayerType(layerIndex: Int32, layerType: Variant.GType
) Sets the type of the custom data layer identified by the given index.
func setOcclusionLayerLightMask(layerIndex: Int32, lightMask: Int32
) Sets the occlusion layer (as in the rendering server) for occluders in the given TileSet occlusion layer.
func setOcclusionLayerSdfCollision(layerIndex: Int32, sdfCollision: Bool
) Enables or disables SDF collision for occluders in the given TileSet occlusion layer.
func setPhysicsLayerCollisionLayer(layerIndex: Int32, layer: UInt32
) Sets the physics layer (as in the physics server) for bodies in the given TileSet physics layer.
func setPhysicsLayerCollisionMask(layerIndex: Int32, mask: UInt32
) Sets the physics layer (as in the physics server) for bodies in the given TileSet physics layer.
func setPhysicsLayerPhysicsMaterial(layerIndex: Int32, physicsMaterial: PhysicsMaterial?
) Sets the physics material for bodies in the given TileSet physics layer.
func setSourceId(Int32, newSourceId: Int32
) Changes a source’s ID.
func setSourceLevelTileProxy(sourceFrom: Int32, sourceTo: Int32
) Creates a source-level proxy for the given source ID. A proxy will map set of tile identifiers to another set of identifiers. Both the atlas coordinates ID and the alternative tile ID are kept the same when using source-level proxies.
func setTerrainColor(terrainSet: Int32, terrainIndex: Int32, color: Color
) Sets a terrain’s color. This color is used for identifying the different terrains in the TileSet editor.
func setTerrainName(terrainSet: Int32, terrainIndex: Int32, name: String
) Sets a terrain’s name.
func setTerrainSetMode(terrainSet: Int32, mode: TileSet.TerrainMode
) Sets a terrain mode. Each mode determines which bits of a tile shape is used to match the neighboring tiles’ terrains.