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
aDecoder
decoder.
-
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
x
x-coordinate.
y
y-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
coord
tile 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
point
screen point.
offset
pixel 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
ofType
tile type.
Return Value
array of tiles.
-
Returns tiles with a property matching the given name.
Declaration
Swift
public func getTilesWithProperty(_ named: String) -> [SKTile]
Parameters
named
property name.
Return Value
array of tiles.
-
Returns tiles matching the given global id.
Declaration
Swift
public func getTiles(globalID: UInt32) -> [SKTile]
Parameters
globalID
tile 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
named
property name.
value
property 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
globalID
global 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
named
type.
Return Value
array of tiles.
-
Add tile data array to the layer and render it.
Declaration
Swift
@discardableResult public func setLayerData(_ data: [UInt32]) -> Bool
Parameters
data
tile 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
coord
tile coordinate
gid
tile id.
tileType
optional tile class name.
Return Value
newly created tile (if successful).
-
Build an empty tile at the given coordinates with a custom texture. Returns
nil
if the coordinate is invalid.Declaration
Swift
public func addTileAt(coord: simd_int2, texture: SKTexture? = nil, tileType: String? = nil) -> SKTile?
Parameters
coord
tile coordinate.
texture
optional tile texture.
tileType
optional 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
x
x-coordinate.
y
y-coordinate.
gid
tile global id.
Return Value
newly created tile (if successful).
-
Build an empty tile at the given coordinates with a custom texture. Returns
nil
if the coordinate is invalid.Declaration
Swift
public func addTileAt(_ x: Int, _ y: Int, texture: SKTexture? = nil) -> SKTile?
Parameters
x
x-coordinate.
y
y-coordinate.
texture
optional 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
coord
tile coordinate
gid
tile id.
tileType
optional 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
coord
map 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
x
x-coordinate.
y
y-coordinate.
Return Value
removed tile, if one exists.
-
Set a tile at the given coordinate.
Declaration
Parameters
coord
coordinate.
tile
tile instance.
Return Value
tile instance.
-
Set a tile at the given coordinate.
Declaration
Parameters
x
x-coordinate.
y
y-coordinate.
tile
tile 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
overlap
tile overlap value.
-
Called when the layer is finished rendering.
Declaration
Swift
public override func didFinishRendering(duration: TimeInterval = 0)
Parameters
duration
fade-in duration.
-
Set a shader for tiles in this layer.
Declaration
Swift
public func setShader(for sktiles: [SKTile], named: String, uniforms: [SKUniform] = [])
Parameters
sktiles
tiles to apply shader to.
named
shader file name.
uniforms
array of shader uniforms.
-
Rasterize a static layer into an image. The resulting texture is stored in the
TiledLayerObject.staticTexture
property.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
restore
restore tile/object texture.
-
Update the tile layer before each frame is rendered.
Declaration
Swift
public override func update(_ currentTime: TimeInterval)
Parameters
currentTime
update 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
spacing
spacing 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
x
x-coordinate.
y
y-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
coord
tile 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
globalID
tile 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
coord
tile coordinate
gid
tile id.
tileType
optional 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
coord
tile coordinate.
texture
optional tile texture.
tileType
optional 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
x
x-coordinate.
y
y-coordinate.
gid
tile 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
coord
map 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
coord
map 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
x
x-coordinate.
y
y-coordinate.
Return Value
removed tile, if one exists.
-
Set a tile at the given coordinate.
Declaration
Parameters
coord
tile coordinate.
tile
tile 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) -> Bool
Parameters
data
tile data.
debug
debug 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
spacing
spacing length.
-
Initialize this layer’s grid graph with an array of walkable tiles.
Declaration
Parameters
walkable
array of walkable tiles.
obstacles
array of obstacle tiles.
diagonalsAllowed
allow diagonal movement in the grid.
withName
optional graph name for identifying in scene.
nodeClass
graph 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
walkableIDs
array of walkable tile ids.
obstacleIDs
array of obstacle tile ids.
diagonalsAllowed
allow diagonal movement in the grid.
nodeClass
graph 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
completion
optional completion closure.