SKTileLayer
public class SKTileLayer : TiledLayerObject
Subclass of TiledLayerObject, the tile layer is a container for an array of tiles (sprites). Tiles maintain a link to the map’s tileset via their SKTilesetData property.
Properties
tileCount: returns a count of valid tiles.
Instance Methods
getTiles(): returns an array of current tilesgetTiles(ofType:): returns tiles of the given typegetTiles(globalID:): returns all tiles matching a global idgetTilesWithProperty(_:_): returns tiles matching the given property & valueanimatedTiles(): returns all animated tilesgetTileData(globalID:): returns all tiles matching a global idtileAt(coord:): returns a tile at the given coordinate, if one exists
Usage
Accessing a tile at a given coordinate:
let tile = tileLayer.tileAt(2, 6)!
Query tiles of a certain type:
let floorTiles = tileLayer.getTiles(ofType: "Floor")
-
Tile chunks.
Declaration
Swift
public var chunks: [SKTileLayerChunk] -
Returns a count of valid tiles.
Declaration
Swift
public var tileCount: Int { get } -
Debug visualization options.
Declaration
Swift
public override var debugDrawOptions: DebugDrawOptions { get set } -
Tile highlight duration
Declaration
Swift
public override var highlightDuration: TimeInterval { get set } -
Speed modifier applied to all actions executed by the layer and its descendants.
Declaration
Swift
public override var speed: CGFloat { get set }
-
Overview
Set the layer tint color. Tiles contained in this layer will be tinted with the given color.
Declaration
Swift
public override var tintColor: SKColor? { get set }
-
Instantiate the node with a decoder instance.
Declaration
Swift
required public init?(coder aDecoder: NSCoder)Parameters
aDecoderdecoder.
-
Returns the number of chunks contained in this layer.
Declaration
Swift
public var chunkCount: Int { get }
-
Returns a tile at the given coordinate, if one exists.
Declaration
Swift
public func tileAt(_ x: Int32, _ y: Int32) -> SKTile?Parameters
xx-coordinate.
yy-coordinate.
Return Value
tile object, if it exists.
-
Returns a tile at the given coordinate, if one exists.
Declaration
Swift
public func tileAt(coord: simd_int2) -> SKTile?Parameters
coordtile coordinate.
Return Value
tile object, if it exists.
-
Returns a tile at the given screen position, if one exists.
Declaration
Swift
public func tileAt(point: CGPoint, offset: CGPoint = CGPoint.zero) -> SKTile?Parameters
pointscreen point.
offsetpixel offset.
Return Value
tile object, if it exists.
-
Returns an array of all tiles in the layer.
Declaration
Swift
public func getTiles() -> [SKTile]Return Value
array of tiles.
-
Returns all of the tiles with a property of the given type.
Declaration
Swift
public func getTiles(ofType: String) -> [SKTile]Parameters
ofTypetile type.
Return Value
array of tiles.
-
Returns tiles with a property matching the given name.
Declaration
Swift
public func getTilesWithProperty(_ named: String) -> [SKTile]Parameters
namedproperty name.
Return Value
array of tiles.
-
Returns tiles matching the given global id.
Declaration
Swift
public func getTiles(globalID: UInt32) -> [SKTile]Parameters
globalIDtile global id.
Return Value
array of tiles.
-
Returns tiles with a property matching the given name & value.
Declaration
Swift
public func getTilesWithProperty(_ named: String, _ value: Any) -> [SKTile]Parameters
namedproperty name.
valueproperty value.
Return Value
array of tiles matching the given property name/value.
-
Returns an array of all the animated tiles in the layer.
Declaration
Swift
public func animatedTiles() -> [SKTile]Return Value
array of animated tiles.
-
Return tile data matching a global id.
Declaration
Swift
public func getTileData(globalID: UInt32) -> SKTilesetData?Parameters
globalIDglobal tile id.
Return Value
tile data (for valid id).
-
Returns tiles with a property of the given type.
Declaration
Swift
public func getTileData(withProperty named: String) -> [SKTilesetData]Parameters
namedtype.
Return Value
array of tiles.
-
Add tile data array to the layer and render it.
Declaration
Swift
@discardableResult public func setLayerData(_ data: [UInt32]) -> BoolParameters
datatile data.
Return Value
data was successfully added.
-
Clear the layer of tiles.
Declaration
Swift
public func clearLayer() -
Build an empty tile at the given coordinates. Returns an existing tile if one already exists, or nil if the coordinate is invalid.
Declaration
Swift
public func addTileAt(coord: simd_int2, globalID: UInt32? = nil, tileType: String? = nil) -> SKTile?Parameters
coordtile coordinate
gidtile id.
tileTypeoptional tile class name.
Return Value
newly created tile (if successful).
-
Build an empty tile at the given coordinates with a custom texture. Returns
nilif the coordinate is invalid.Declaration
Swift
public func addTileAt(coord: simd_int2, texture: SKTexture? = nil, tileType: String? = nil) -> SKTile?Parameters
coordtile coordinate.
textureoptional tile texture.
tileTypeoptional tile type.
Return Value
newly created tile.
-
Build an empty tile at the given coordinates. Returns an existing tile if one already exists, or nil if the coordinate is invalid.
Declaration
Swift
public func addTileAt(_ x: Int, _ y: Int, globalID: UInt32? = nil) -> SKTile?Parameters
xx-coordinate.
yy-coordinate.
gidtile global id.
Return Value
newly created tile (if successful).
-
Build an empty tile at the given coordinates with a custom texture. Returns
nilif the coordinate is invalid.Declaration
Swift
public func addTileAt(_ x: Int, _ y: Int, texture: SKTexture? = nil) -> SKTile?Parameters
xx-coordinate.
yy-coordinate.
textureoptional tile texture.
Return Value
newly created tile (if successful).
-
Replace an existing tile at the given coordinates. Returns an existing tile if one already exists, or nil if the coordinate is invalid.
Declaration
Parameters
coordtile coordinate
gidtile id.
tileTypeoptional tile class name.
Return Value
tuple of current tile (if it exists) & newly created tile (if successful).
-
Clear all tiles.
Declaration
Swift
public func clearTiles() -
Remove the tile at a given coordinate.
Declaration
Swift
@discardableResult public func removeTile(at coord: simd_int2) -> SKTile?Parameters
coordmap coordinate.
Return Value
removed tile, if one exists.
-
Remove the tile at the given x/y coordinates.
Declaration
Swift
@discardableResult public func removeTile(_ x: Int, _ y: Int) -> SKTile?Parameters
xx-coordinate.
yy-coordinate.
Return Value
removed tile, if one exists.
-
Set a tile at the given coordinate.
Declaration
Parameters
coordcoordinate.
tiletile instance.
Return Value
tile instance.
-
Set a tile at the given coordinate.
Declaration
Parameters
xx-coordinate.
yy-coordinate.
tiletile instance.
Return Value
tile instance.
-
Setup tile collisions.
Declaration
Swift
public override func setupTileCollisions()
-
Set the tile overlap. Valid values are (0 - 1.0).
Declaration
Swift
public func setTileOverlap(_ overlap: CGFloat)Parameters
overlaptile overlap value.
-
Called when the layer is finished rendering.
Declaration
Swift
public override func didFinishRendering(duration: TimeInterval = 0)Parameters
durationfade-in duration.
-
Set a shader for tiles in this layer.
Declaration
Swift
public func setShader(for sktiles: [SKTile], named: String, uniforms: [SKUniform] = [])Parameters
sktilestiles to apply shader to.
namedshader file name.
uniformsarray of shader uniforms.
-
Rasterize a static layer into an image. The resulting texture is stored in the
TiledLayerObject.staticTextureproperty.Declaration
Swift
public override func rasterizeStaticLayer()
-
Run animation actions on all of the tiles in this layer.
Declaration
Swift
public override func runAnimationAsActions() -
Remove tile animations.
Declaration
Swift
public override func removeAnimationActions(restore: Bool = false)Parameters
restorerestore tile/object texture.
-
Update the tile layer before each frame is rendered.
Declaration
Swift
public override func update(_ currentTime: TimeInterval)Parameters
currentTimeupdate interval.
-
Returns a custom mirror for this layer.
Declaration
Swift
public override var customMirror: Mirror { get }
-
Dump the contents of the tile data array to the console.
Declaration
Swift
public func dumpTileLayerData(spacing: Int = 3)Parameters
spacingspacing length.
-
Returns an array of valid tiles.
Declaration
Swift
@available(*, deprecated, message: "use `getTiles(﹚` instead") public func validTiles() -> [SKTile]Return Value
array of current tiles.
-
Returns a tile at the given coordinate, if one exists.
Declaration
Swift
@available(*, deprecated, renamed: "tileAt(_:_:﹚") public func tileAt(_ x: Int, _ y: Int) -> SKTile?Parameters
xx-coordinate.
yy-coordinate.
Return Value
tile object, if it exists.
-
Returns a tile at the given coordinate, if one exists.
Declaration
Swift
@available(*, deprecated, renamed: "tileAt(coord:﹚") public func tileAt(coord: CGPoint) -> SKTile?Parameters
coordtile coordinate.
Return Value
tile object, if it exists.
-
Returns tiles matching the given global id.
Declaration
Swift
@available(*, deprecated, renamed: "getTiles(globalID:﹚") public func getTiles(globalID: Int) -> [SKTile]Parameters
globalIDtile global id.
Return Value
array of tiles.
-
Build an empty tile at the given coordinates. Returns an existing tile if one already exists, or nil if the coordinate is invalid.
Declaration
Swift
@available(*, deprecated, renamed: "addTileAt(coord:globalID:tileType:﹚") public func addTileAt(coord: CGPoint, gid: Int? = nil, tileType: String? = nil) -> SKTile?Parameters
coordtile coordinate
gidtile id.
tileTypeoptional tile class name.
Return Value
newly created tile (if successful).
-
Build an empty tile at the given coordinates with a custom texture. Returns nil is the coordinate is invalid.
Declaration
Swift
@available(*, deprecated, renamed: "addTileAt(coord:texture:tileType:﹚") public func addTileAt(coord: CGPoint, texture: SKTexture? = nil, tileType: String? = nil) -> SKTile?Parameters
coordtile coordinate.
textureoptional tile texture.
tileTypeoptional tile type.
Return Value
newly created tile.
-
Build an empty tile at the given coordinates. Returns an existing tile if one already exists, or nil if the coordinate is invalid.
Declaration
Swift
@available(*, deprecated, renamed: "addTileAt(x:y:gid:﹚") public func addTileAt(_ x: Int, _ y: Int, gid: Int? = nil) -> SKTile?Parameters
xx-coordinate.
yy-coordinate.
gidtile global id.
Return Value
newly created tile (if successful).
-
Remove the tile at a given coordinate.
Declaration
Swift
@available(*, deprecated, renamed: "removeTile(at:﹚") public func removeTileAt(coord: CGPoint) -> SKTile?Parameters
coordmap coordinate.
Return Value
removed tile, if one exists.
-
Remove the tile at a given coordinate.
Declaration
Swift
@available(*, deprecated, renamed: "removeTile(at:﹚") public func removeTileAt(coord: simd_int2) -> SKTile?Parameters
coordmap coordinate.
Return Value
removed tile, if one exists.
-
Remove the tile at the given x/y coordinates.
Declaration
Swift
@available(*, deprecated, renamed: "removeTile(_:﹚") public func removeTileAt(_ x: Int, _ y: Int) -> SKTile?Parameters
xx-coordinate.
yy-coordinate.
Return Value
removed tile, if one exists.
-
Set a tile at the given coordinate.
Declaration
Parameters
coordtile coordinate.
tiletile instance.
Return Value
tile instance.
-
Add tile data array to the layer and render it.
Declaration
Swift
@available(*, deprecated, renamed: "setLayerData(_:﹚") @discardableResult public func setLayerData(_ data: [UInt32], debug: Bool = false) -> BoolParameters
datatile data.
debugdebug mode.
Return Value
data was successfully added.
-
Dump the contents of the tile data array to the console.
Declaration
Swift
@available(*, deprecated, renamed: "dumpTileLayerData(spacing:﹚") public func dumpLayerData(spacing: Int = 3)Parameters
spacingspacing length.
-
Initialize this layer’s grid graph with an array of walkable tiles.
Declaration
Parameters
walkablearray of walkable tiles.
obstaclesarray of obstacle tiles.
diagonalsAllowedallow diagonal movement in the grid.
withNameoptional graph name for identifying in scene.
nodeClassgraph node type.
Return Value
navigation graph, if created.
-
Initialize layer navigation graph by not specifying tiles to utilize.
Declaration
Swift
@discardableResult public func initializeGraph() -> GKGridGraph<GKGridGraphNode>?Return Value
navigation graph, if created.
-
Initialize this layer’s grid graph with an array of walkable & obstacle tile ids.
Declaration
Swift
@discardableResult public func initializeGraph(walkableIDs: [Int], obstacleIDs: [Int] = [], diagonalsAllowed: Bool = false, nodeClass: String? = nil) -> GKGridGraph<GKGridGraphNode>?Parameters
walkableIDsarray of walkable tile ids.
obstacleIDsarray of obstacle tile ids.
diagonalsAllowedallow diagonal movement in the grid.
nodeClassgraph node type.
Return Value
navigation graph, if created.
-
Return tiles with walkable data attributes.
Declaration
Swift
public func gatherWalkable() -> [SKTile]Return Value
array of tiles with walkable attribute.
-
Return tiles with obstacle data attributes.
Declaration
Swift
public func gatherObstacles() -> [SKTile]Return Value
array of tiles with obstacle attribute.
-
Parse the tile layer’s properties.
Declaration
Swift
public override func parseProperties(completion: (() -> Void)?)Parameters
completionoptional completion closure.
View on GitHub
Install in Dash
SKTileLayer Class Reference