SKTilemap
public class SKTilemap : SKEffectNode, SKTiledObject
Overview
The SKTilemap
class is a container for managing layers of tiles (sprites),
vector objects & images. Tile data is stored in SKTileset
tile sets.
Usage
Maps can be loaded with the class function SKTilemap.load(tmxFile:)
:
if let tilemap = SKTilemap.load(tmxFile: "myfile.tmx") {
scene.addChild(tilemap)
}
Properties
Property | Description |
---|---|
mapSize | Size of the map (in tiles). |
tileSize | Map tile size (in pixels). |
renderSize | Size of the map in pixels. |
orientation | Map orientation (orthogonal, isometric, etc.) |
bounds | Map bounding rect. |
tilesets | Array of stored tileset instances. |
allowZoom | Allow camera zooming. |
layers | Array of child layers. |
-
Overview
Enum describing map orientation type.
Constants
Property Description orthogonal Orthogonal(square tiles) tile map. isometric Isometric tile map. hexagonal Hexagonal tile map. staggered Staggered isometric tile map. Declaration
Swift
public enum TilemapOrientation : String
-
▶︎url
Tilemap source file path.
Declaration
Swift
public var url: URL!
-
▶︎uuid
Unique SpriteKit node id.
Declaration
Swift
public var uuid: String
-
Indicates the Tiled application version this map was created with.
Declaration
Swift
public internal(set) var tiledversion: String! { get }
-
Indicates the Tiled map version.
Declaration
Swift
public internal(set) var mapversion: String! { get }
-
▶︎type
Tilemap node type.
Declaration
Swift
public var type: String!
-
Custom Tiled properties.
Declaration
Swift
public var properties: [String : String]
-
If enabled, custom Tiled properties are ignored.
Declaration
Swift
public var ignoreProperties: Bool
-
Returns true if all of the child layers are rendered.
Declaration
Swift
public internal(set) var isRendered: Bool { get }
-
Returns the render time of this map.
Declaration
Swift
public internal(set) var mapRenderTime: TimeInterval { get }
-
▶︎size
Size of map (in tiles).
Declaration
Swift
public var size: CGSize
-
▶︎tileSize
Tile size (in pixels).
Declaration
Swift
public var tileSize: CGSize
-
Map orientation type.
Declaration
Swift
public var orientation: TilemapOrientation
-
Map display name. Defaults to the current map source file name (minus the tmx extension).
Declaration
Swift
public var displayName: String?
-
▶︎mapName
String representing the map name. Defaults to the current map source file name (minus the tmx extension).
Declaration
Swift
public var mapName: String { get }
-
Update mode used for tiles & objects.
Declaration
Swift
public var updateMode: TileUpdateMode { get set }
-
Scaling factor for text objects, etc.
Declaration
Swift
public var renderQuality: CGFloat { get set }
-
▶︎speed
Map animation speed
Declaration
Swift
override public var speed: CGFloat { get set }
-
Render statistics
Declaration
Swift
public struct CameraZoomConstraints
-
Indicates map should auto-resize upon view changes.
Declaration
Swift
public internal(set) var autoResize: Bool { get }
-
▶︎bounds
Map bounds.
Declaration
Swift
public var bounds: CGRect
-
Receive notifications from camera.
Declaration
Swift
public var receiveCameraUpdates: Bool
-
Display bounds that the tilemap is viewable in.
Declaration
Swift
public var cameraBounds: CGRect?
-
Initial world scale
Declaration
Swift
public var worldScale: CGFloat
-
Map zoom level
Declaration
Swift
public var currentZoom: CGFloat
-
Allow camera zooming.
Declaration
Swift
public var allowZoom: Bool
-
Allow camera movement.
Declaration
Swift
public var allowMovement: Bool
-
▶︎firstGID
First global id value.
Declaration
Swift
public var firstGID: Int
-
▶︎tilesets
Current tilesets.
Declaration
Swift
public var tilesets: Set<SKTileset>
-
Layer count.
Declaration
Swift
public var layerCount: Int { get }
-
Object count.
Declaration
Swift
public var objectCount: Int { get }
-
Default z-position range between layers.
Declaration
Swift
public var zDeltaForLayers: CGFloat
-
Render statistics structure.
See moreDeclaration
Swift
public struct RenderStatistics
-
▶︎layers
Returns a flattened array of child layers.
Declaration
Swift
public var layers: [SKTiledLayerObject] { get }
-
Ignore Tiled background color.
Declaration
Swift
public var ignoreBackground: Bool { get set }
-
Optional background color (read from the Tiled file)
Declaration
Swift
public var backgroundColor: SKColor? { get set }
-
Debug visualization options.
Declaration
Swift
public var debugDrawOptions: DebugDrawOptions { get set }
-
Overlay color.
Declaration
Swift
public var overlayColor: SKColor
-
▶︎gravity
dynamics
Declaration
Swift
public var gravity: CGVector
-
▶︎delegate
Reference to
SKTilemapDelegate
delegate.Declaration
Swift
weak public var delegate: SKTilemapDelegate?
-
▶︎frame
Map frame.
Declaration
Swift
override public var frame: CGRect { get }
-
Object vertices.
Declaration
Swift
public func getVertices() -> [CGPoint]
-
Size of the map in points.
Declaration
Swift
public var sizeInPoints: CGSize { get }
-
▶︎lastGID
Returns the last GID for all of the tilesets.
Declaration
Swift
public var lastGID: Int { get }
-
Returns the last index for all tilesets.
Declaration
Swift
public var lastIndex: Int { get }
-
Returns the last (highest) z-position in the map.
Declaration
Swift
public var lastZPosition: CGFloat { get }
-
Tile overlap amount. 1 is typically a good value.
Declaration
Swift
public var tileOverlap: CGFloat { get set }
-
Global property to show/hide all
SKTileObject
objects.Declaration
Swift
public var showObjects: Bool { get set }
-
Show objects for the given layers.
Declaration
Swift
public func showObjects(forLayers: [SKTiledLayerObject])
Parameters
forLayers
[SKTiledLayerObject]
array of layers.Return Value
[SKTileLayer]
array of tile layers. -
Return all tile layers. If recursive is false, only returns top-level layers.
Declaration
Swift
public func tileLayers(recursive: Bool = true) -> [SKTileLayer]
Parameters
recursive
Bool
include nested layers.Return Value
[SKTileLayer]
array of tile layers. -
Return all object groups. If recursive is false, only returns top-level layers.
Declaration
Swift
public func objectGroups(recursive: Bool = true) -> [SKObjectGroup]
Parameters
recursive
Bool
include nested layers.Return Value
[SKObjectGroup]
array of object groups. -
Return all image layers. If recursive is false, only returns top-level layers.
Declaration
Swift
public func imageLayers(recursive: Bool = true) -> [SKImageLayer]
Parameters
recursive
Bool
include nested layers.Return Value
[SKImageLayer]
array of image layers. -
Return all group layers. If recursive is false, only returns top-level layers.
Declaration
Swift
public func groupLayers(recursive: Bool = true) -> [SKGroupLayer]
Parameters
recursive
Bool
include nested layers.Return Value
[SKGroupLayer]
array of image layers. -
Convenience property to return all group layers.
Declaration
Swift
public var groupLayers: [SKGroupLayer] { get }
-
Global antialiasing of lines
Declaration
Swift
public var antialiasLines: Bool { get set }
-
Global tile count
Declaration
Swift
public var tileCount: Int { get }
-
▶︎isPaused
Pauses the node, and colors all of its children darker.
Declaration
Swift
override public var isPaused: Bool { get set }
-
Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String) -> SKTilemap?
Parameters
tmxFile
String
Tiled file name.Return Value
SKTilemap?
tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, _ completion: ((_ tilemap: SKTilemap) -> Void)? = nil) -> SKTilemap?
Parameters
tmxFile
String
Tiled file name.completion
((_ tilemap: SKTilemap) -> Void)?
optional completion block.Return Value
SKTilemap?
tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, loggingLevel: LoggingLevel) -> SKTilemap?
Parameters
tmxFile
String
Tiled file name.loggingLevel
LoggingLevel
logging verbosity level.Return Value
SKTilemap?
tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate) -> SKTilemap?
Parameters
tmxFile
String
Tiled file name.delegate
SKTilemapDelegate
tilemap delegate instance.Return Value
SKTilemap?
tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate, updateMode: TileUpdateMode) -> SKTilemap?
Parameters
tmxFile
String
Tiled file name.delegate
SKTilemapDelegate
tilemap delegate instance.updateMode
TileUpdateMode
tile update mode.Return Value
SKTilemap?
tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate, tilesetDataSource: SKTilesetDataSource) -> SKTilemap?
Parameters
tmxFile
String
Tiled file name.delegate
SKTilemapDelegate
tilemap delegate instance.tilesetDataSource
Return Value
SKTilemap?
tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate, tilesetDataSource: SKTilesetDataSource, updateMode: TileUpdateMode) -> SKTilemap?
Parameters
tmxFile
String
Tiled file name.delegate
SKTilemapDelegate
tilemap delegate instance.tilesetDataSource
updateMode
TileUpdateMode
tile update mode.Return Value
SKTilemap?
tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate, tilesetDataSource: SKTilesetDataSource, withTilesets: [SKTileset]) -> SKTilemap?
Parameters
tmxFile
String
Tiled file name.delegate
SKTilemapDelegate
tilemap delegate instance.tilesetDataSource
withTilesets
[SKTileset]
pre-loaded tilesets.Return Value
SKTilemap?
tilemap object (if file read succeeds). -
▶︎load(tmxFile:
inDirectory: delegate: tilesetDataSource: updateMode: withTilesets: ignoreProperties: loggingLevel: _: ) Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, inDirectory: String? = nil, delegate: SKTilemapDelegate? = nil, tilesetDataSource: SKTilesetDataSource? = nil, updateMode: TileUpdateMode = TiledGlobals.default.updateMode, withTilesets: [SKTileset]? = nil, ignoreProperties noparse: Bool = false, loggingLevel: LoggingLevel = TiledGlobals.default.loggingLevel, _ completion: ((_ tilemap: SKTilemap) -> Void)? = nil) -> SKTilemap?
Parameters
tmxFile
String
Tiled file name.inDirectory
String?
search path for assets.delegate
SKTilemapDelegate?
optionalSKTilemapDelegate
instance.tilesetDataSource
SKTilesetDataSource?
optionalSKTilesetDataSource
instance.updateMode
TileUpdateMode
tile update mode.withTilesets
[SKTileset]?
optional tilesets.ignoreProperties
Bool
ignore custom properties from Tiled.loggingLevel
LoggingLevel
logging verbosity level.completion
((_ tilemap: SKTilemap) -> Void)?
optional completion block.Return Value
SKTilemap?
tilemap object (if file read succeeds).
-
Default initializer.
Declaration
Swift
required public init?(coder aDecoder: NSCoder)
-
Initialize with dictionary attributes from xml parser.
Declaration
Swift
public init?(attributes: [String : String])
Parameters
attributes
Dictionary
attributes dictionary.Return Value
SKTilemap?
-
Initialize with map size/tile size
Declaration
Swift
public init(_ sizeX: Int, _ sizeY: Int, _ tileSizeX: Int, _ tileSizeY: Int, orientation: TilemapOrientation = .orthogonal)
Parameters
sizeX
Int
map width in tiles.sizeY
Int
map height in tiles.tileSizeX
Int
tile width in pixels.tileSizeY
Int
tile height in pixels.Return Value
SKTilemap
-
Remove a tileset from the tilesets set.
Parameters
tileset
SKTileset
removed tileset. -
Returns a named tileset from the tilesets set.
Declaration
Swift
public func getTileset(named: String) -> SKTileset?
Parameters
named
String
tileset to return.Return Value
SKTileset?
tileset object. -
Returns an external tileset with a given filename.
Declaration
Swift
public func getTileset(fileNamed filename: String) -> SKTileset?
Parameters
filename
String
tileset source file.Return Value
SKTileset?
-
Returns the tileset associated with a global id.
Declaration
Swift
public func getTileset(forTile: Int) -> SKTileset?
Parameters
forTile
Int
tile global id.Return Value
SKTileset?
associated tileset.
-
Returns a point for a given coordinate in the layer, with optional offset values for x/y.
Declaration
Swift
public func pointForCoordinate(coord: CGPoint, offsetX: CGFloat = 0, offsetY: CGFloat = 0) -> CGPoint
Parameters
coord
CGPoint
tile coordinate.offsetX
CGFloat
x-offset value.offsetY
CGFloat
y-offset value.Return Value
CGPoint
point in layer. -
Returns a tile coordinate for a given vector_int2 coordinate.
Declaration
Swift
public func pointForCoordinate(vec2: int2) -> CGPoint
Parameters
vec2
int2
vector int2 coordinate.Return Value
CGPoint
position in layer. -
Returns a tile coordinate for a given point in the layer.
Declaration
Swift
public func coordinateForPoint(_ point: CGPoint) -> CGPoint
Parameters
point
CGPoint
point in layer.Return Value
CGPoint
tile coordinate. -
Returns a tile coordinate for a given point in the layer as a vector_int2.
Declaration
Swift
public func vectorCoordinateForPoint(_ point: CGPoint) -> int2
Parameters
point
CGPoint
point in layer.Return Value
int2
tile coordinate.
-
Returns an array of child layers, sorted by index (first is lowest, last is highest).
Declaration
Swift
public func getLayers(recursive: Bool = true) -> [SKTiledLayerObject]
Parameters
recursive
Bool
include nested layers.Return Value
[SKTiledLayerObject]
array of layers. -
Returns all content layers (ie. not groups). Sorted by zPosition in scene.
Declaration
Swift
public func getContentLayers() -> [SKTiledLayerObject]
Return Value
[SKTiledLayerObject]
array of layers. -
Returns an array of layer names.
Declaration
Swift
public func layerNames() -> [String]
Return Value
[String]
layer names. -
Add a layer to the current layers set. Automatically sets zPosition based on the
SKTilemap.zDeltaForLayers
property. If thegroup
argument is not nil, layer will be added to the group instead.Declaration
Swift
@discardableResult public func addLayer(_ layer: SKTiledLayerObject, group: SKGroupLayer? = nil, clamped: Bool = true) -> (success: Bool, layer: SKTiledLayerObject)
Parameters
layer
SKTiledLayerObject
layer object.group
SKGroupLayer?
optional group layer.clamped
Bool
clamp position to nearest pixel.Return Value
(success: Bool, layer: SKTiledLayerObject)
add was successful, layer added. -
Remove a layer from the current layers set.
Declaration
Swift
public func removeLayer(_ layer: SKTiledLayerObject) -> SKTiledLayerObject?
Parameters
layer
SKTiledLayerObject
layer object.Return Value
SKTiledLayerObject?
removed layer. -
Create and add a new tile layer.
Declaration
Swift
@discardableResult public func newTileLayer(named: String, group: SKGroupLayer? = nil) -> SKTileLayer
Parameters
named
String
layer name.group
SKGroupLayer?
optional group layer.Return Value
SKTileLayer
new layer. -
Create and add a new object group.
Declaration
Swift
@discardableResult public func newObjectGroup(named: String, group: SKGroupLayer? = nil) -> SKObjectGroup
Parameters
named
String
layer name.group
SKGroupLayer?
optional group layer.Return Value
SKObjectGroup
new layer. -
Create and add a new image layer.
Declaration
Swift
@discardableResult public func newImageLayer(named: String, group: SKGroupLayer? = nil) -> SKImageLayer
Parameters
named
String
layer name.group
SKGroupLayer?
optional group layer.Return Value
SKImageLayer
new layer. -
Create and add a new group layer.
Declaration
Swift
@discardableResult public func newGroupLayer(named: String, group: SKGroupLayer? = nil) -> SKGroupLayer
Parameters
named
String
layer name.group
SKGroupLayer?
optional group layer.Return Value
SKGroupLayer
new layer. -
Return layers matching the given name.
Declaration
Swift
public func getLayers(named layerName: String, recursive: Bool = true) -> [SKTiledLayerObject]
Parameters
name
String
tile layer name.recursive
Bool
include nested layers.Return Value
[SKTiledLayerObject]
layer objects. -
Return layers with names matching the given prefix.
Declaration
Swift
public func getLayers(withPrefix: String, recursive: Bool = true) -> [SKTiledLayerObject]
Parameters
withPrefix
String
prefix to match.recursive
Bool
include nested layers.Return Value
[SKTiledLayerObject]
layer objects. -
Return layers at the given path.
Declaration
Swift
public func getLayers(atPath: String) -> [SKTiledLayerObject]
Parameters
atPath
String
layer path.Return Value
[SKTiledLayerObject]
layer objects. -
Returns a layer matching the given UUID.
Declaration
Swift
public func getLayer(withID uuid: String) -> SKTiledLayerObject?
Parameters
uuid
String
tile layer UUID.Return Value
SKTiledLayerObject?
layer object. -
Returns a layer given the index (0 being the lowest).
Declaration
Swift
public func getLayer(atIndex index: Int) -> SKTiledLayerObject?
Parameters
index
Int
layer index.Return Value
SKTiledLayerObject?
layer object. -
Return layers assigned a custom
type
property.Declaration
Swift
public func getLayers(ofType: String, recursive: Bool = true) -> [SKTiledLayerObject]
Parameters
ofType
String
layer type.recursive
Bool
include nested layers.Return Value
[SKTiledLayerObject]
array of layers. -
Return tile layers matching the given name. If recursive is false, only returns top-level layers.
Declaration
Swift
public func tileLayers(named layerName: String, recursive: Bool = true) -> [SKTileLayer]
Parameters
named
String
tile layer name.recursive
Bool
include nested layers.Return Value
[SKTileLayer]
array of tile layers. -
Return tile layers with names matching the given prefix. If recursive is false, only returns top-level layers.
Declaration
Swift
public func tileLayers(withPrefix: String, recursive: Bool = true) -> [SKTileLayer]
Parameters
withPrefix
String
prefix to match.recursive
Bool
include nested layers.Return Value
[SKTileLayer]
array of tile layers. -
Returns a tile layer at the given index, otherwise, nil.
Declaration
Swift
public func tileLayer(atIndex index: Int) -> SKTileLayer?
Parameters
atIndex
Int
layer index.Return Value
SKTileLayer?
matching tile layer. -
Return object groups matching the given name. If recursive is false, only returns top-level layers.
Declaration
Swift
public func objectGroups(named layerName: String, recursive: Bool = true) -> [SKObjectGroup]
Parameters
named
String
tile layer name.recursive
Bool
include nested layers.Return Value
[SKObjectGroup]
array of object groups. -
Return object groups with names matching the given prefix. If recursive is false, only returns top-level layers.
Declaration
Swift
public func objectGroups(withPrefix: String, recursive: Bool = true) -> [SKObjectGroup]
Parameters
withPrefix
String
prefix to match.recursive
Bool
include nested layers.Return Value
[SKObjectGroup]
array of object groups. -
Returns an object group at the given index, otherwise, nil.
Declaration
Swift
public func objectGroup(atIndex index: Int) -> SKObjectGroup?
Parameters
atIndex
Int
layer index.Return Value
SKObjectGroup?
matching group layer. -
Return image layers matching the given name. If recursive is false, only returns top-level layers.
Declaration
Swift
public func imageLayers(named layerName: String, recursive: Bool = true) -> [SKImageLayer]
Parameters
named
String
tile layer name.recursive
Bool
include nested layers.Return Value
[SKImageLayer]
array of image layers. -
Return image layers with names matching the given prefix. If recursive is false, only returns top-level layers.
Declaration
Swift
public func imageLayers(withPrefix: String, recursive: Bool = true) -> [SKImageLayer]
Parameters
withPrefix
String
prefix to match.recursive
Bool
include nested layers.Return Value
[SKImageLayer]
array of image layers. -
Returns an image layer at the given index, otherwise, nil.
Declaration
Swift
public func imageLayer(atIndex index: Int) -> SKImageLayer?
Parameters
atIndex
Int
layer index.Return Value
SKImageLayer?
matching image layer. -
Return group layers matching the given name. If recursive is false, only returns top-level layers.
Declaration
Swift
public func groupLayers(named layerName: String, recursive: Bool = true) -> [SKGroupLayer]
Parameters
named
String
tile layer name.recursive
Bool
include nested layers.Return Value
[SKGroupLayer]
array of group layers. -
Return group layers with names matching the given prefix. If recursive is false, only returns top-level layers.
Declaration
Swift
public func groupLayers(withPrefix: String, recursive: Bool = true) -> [SKGroupLayer]
Parameters
withPrefix
String
prefix to match.recursive
Bool
include nested layers.Return Value
[SKGroupLayer]
array of group layers. -
Returns an group layer at the given index, otherwise, nil.
Declaration
Swift
public func groupLayer(atIndex index: Int) -> SKGroupLayer?
Parameters
atIndex
Int
layer index.Return Value
SKGroupLayer?
matching group layer. -
Sort the layers in z based on a starting value (defaults to the current zPosition).
Declaration
Swift
public func sortLayers(from: CGFloat? = nil)
Parameters
from
CGFloat?
optional starting z-positon.
-
Return tiles at the given point (all tile layers).
Declaration
Swift
public func tilesAt(point: CGPoint) -> [SKTile]
Parameters
point
CGPoint
position in tilemap.Return Value
[SKTile]
array of tiles. -
Return tiles at the given coordinate (all tile layers).
Declaration
Swift
public func tilesAt(coord: CGPoint) -> [SKTile]
Parameters
coord
CGPoint
coordinate.Return Value
[SKTile]
array of tiles. -
Return tiles at the given coordinate (all tile layers).
Declaration
Swift
public func tilesAt(_ x: Int, _ y: Int) -> [SKTile]
Parameters
x
Int
x-coordinate.y
Int
- y-coordinate.Return Value
[SKTile]
array of tiles. -
Returns a tile at the given coordinate from a layer.
Declaration
Swift
public func tileAt(coord: CGPoint, inLayer named: String?) -> SKTile?
Parameters
coord
CGPoint
tile coordinate.inLayer
String?
layer name.Return Value
SKTile?
tile, or nil. -
Returns a tile at the given coordinate from a layer.
Declaration
Swift
public func tileAt(_ x: Int, _ y: Int, inLayer named: String?) -> SKTile?
Parameters
x
Int
tile x-coordinate.y
Int
tile y-coordinate.named
String?
layer name.Return Value
SKTile?
tile, or nil. -
Returns all tiles in the map. If recursive is false, only returns tiles from top-level layers.
Declaration
Swift
public func getTiles(recursive: Bool = true) -> [SKTile]
Parameters
recursive
Bool
include nested layers.Return Value
[SKTile]
array of tiles. -
Returns tiles with a property of the given type. If recursive is false, only returns tiles from top-level layers.
Declaration
Swift
public func getTiles(ofType: String, recursive: Bool = true) -> [SKTile]
Parameters
ofType
String
type.recursive
Bool
include nested layers.Return Value
[SKTile]
array of tiles. -
Returns tiles with the given global id. If recursive is false, only returns tiles from top-level layers.
Declaration
Swift
public func getTiles(globalID: Int, recursive: Bool = true) -> [SKTile]
Parameters
globalID
Int
tile globla id.recursive
Bool
include nested layers.Return Value
[SKTile]
array of tiles. -
Returns tiles with a property of the given type & value. If recursive is false, only returns tiles from top-level layers.
Declaration
Swift
public func getTilesWithProperty(_ named: String, _ value: Any, recursive: Bool = true) -> [SKTile]
Parameters
named
String
property name.value
Any
property value.recursive
Bool
include nested layers.Return Value
[SKTile]
array of tiles. -
Returns an array of all animated tile objects.
Declaration
Swift
public func animatedTiles(recursive: Bool = true) -> [SKTile]
Return Value
[SKTile]
array of tiles. -
Return the top-most tile at the given coordinate.
Declaration
Swift
public func firstTileAt(coord: CGPoint) -> SKTile?
Parameters
coord
CGPoint
coordinate.Return Value
SKTile?
first tile in layers.
-
Returns data for a global tile id.
Declaration
Swift
public func getTileData(globalID gid: Int) -> SKTilesetData?
Parameters
globalID
Int
global tile id.Return Value
SKTilesetData
tile data, if it exists. -
Return tile data with a property of the given type.
Declaration
Swift
public func getTileData(ofType: String) -> [SKTilesetData]
Parameters
ofType
String
tile data type.Return Value
[SKTilesetData]
array of tile data. -
Return tile data with a property of the given type (all tilesets).
Declaration
Swift
public func getTileData(withProperty named: String) -> [SKTilesetData]
Parameters
named
String
property name.Return Value
[SKTilesetData]
array of tile data. -
Return tile data with a property of the given type (all tile layers).
Declaration
Swift
public func getTileData(withProperty named: String, _ value: Any) -> [SKTilesetData]
Parameters
named
String
property name.value
Any
property value.Return Value
[SKTile]
array of tiles. -
Returns tile data with the given name & animated state.
Declaration
Swift
public func getTileData(named name: String, isAnimated: Bool = false) -> [SKTilesetData]
Parameters
named
String
data name.isAnimated
Bool
filter data that is animated.Return Value
[SKTilesetData]
array of tile data.
-
Return obejects at the given point (all object groups).
Declaration
Swift
public func objectsAt(point: CGPoint) -> [SKTileObject]
Parameters
coord
CGPoint
coordinate.Return Value
[SKTileObject]
array of objects. -
Return all of the current tile objects. If recursive is false, only returns objects from top-level layers.
Declaration
Swift
public func getObjects(recursive: Bool = true) -> [SKTileObject]
Parameters
recursive
Bool
include nested layers.Return Value
[SKTileObject]
array of objects. -
Return objects matching a given type. If recursive is false, only returns objects from top-level layers.
Declaration
Swift
public func getObjects(ofType: String, recursive: Bool = true) -> [SKTileObject]
Parameters
ofType
String
object type to query.recursive
Bool
include nested layers.Return Value
[SKTileObject]
array of objects. -
Return objects matching a given name. If recursive is false, only returns objects from top-level layers.
Declaration
Swift
public func getObjects(named: String, recursive: Bool = true) -> [SKTileObject]
Parameters
named
String
object name to query.recursive
Bool
include nested layers.Return Value
[SKTileObject]
array of objects. -
Return objects with the given text value. If recursive is false, only returns objects from top-level layers.
Declaration
Swift
public func getObjects(withText text: String, recursive: Bool = true) -> [SKTileObject]
Parameters
withText
String
text value.recursive
Bool
include nested layers.Return Value
[SKTileObject]
array of objects. -
Returns an object with the given id.
Declaration
Swift
public func getObject(withID id: Int) -> SKTileObject?
Parameters
id
Int
Object id.Return Value
SKTileObject?
-
Return objects with a tile id. If recursive is false, only returns objects from top-level layers.
Declaration
Swift
public func tileObjects(recursive: Bool = true) -> [SKTileObject]
Parameters
recursive
Bool
include nested layers.Return Value
[SKTileObject]
objects with a tile gid. -
Return objects with a tile id. If recursive is false, only returns objects from top-level layers.
Declaration
Swift
public func tileObjects(globalID: Int, recursive: Bool = true) -> [SKTileObject]
Parameters
globalID
Int
global tile id.recursive
Bool
include nested layers.Return Value
[SKTileObject]
objects with a tile gid. -
Return text objects. If recursive is false, only returns objects from top-level layers.
Declaration
Swift
public func textObjects(recursive: Bool = true) -> [SKTileObject]
Parameters
recursive
Bool
include nested layers.Return Value
[SKTileObject]
text objects.
-
Returns true if the coordinate is valid.
Declaration
Swift
public func isValid(coord: CGPoint) -> Bool
Parameters
coord
CGPoint
tile coordinate.Return Value
Bool
coodinate is valid. -
Returns a touch location in negative-y space.
Position is in converted space
-
Returns the tile coordinate at a touch location.
-
Returns a mouse event location in the default layer. (negative-y space).
Position is in converted space
Declaration
Swift
public func mouseLocation(event: NSEvent) -> CGPoint
Parameters
point
CGPoint
scene point.Return Value
CGPoint
converted point in layer coordinate system. -
Returns the tile coordinate at a mouse event location.
Declaration
Swift
public func coordinateAtMouseEvent(event: NSEvent) -> CGPoint
Parameters
event
NSEvent
mouse event location.Return Value
CGPoint
converted point in layer coordinate system.
-
Set a shader for the tile layer.
Declaration
Swift
public func setShader(named: String, uniforms: [SKUniform] = [])
Parameters
named
String
shader file name.uniforms
[SKUniform]
array of shader uniforms.
-
Called when parser has finished reading the map.
Declaration
Swift
public func didFinishParsing(timeStarted: Date, tasks: Int = 0)
Parameters
timeStarted
Date
render start time.tasks
Int
number of tasks to complete. -
Called when parser has finished rendering the map.
Declaration
Swift
public func didFinishRendering(timeStarted: Date)
Parameters
timeStarted
Date
render start time.
-
Run layer animations as SpriteKit actions.
Declaration
Swift
public func runAnimationAsActions(_ value: Bool, restore: Bool = true)
Parameters
value
Bool
on/off toggle.restore
Bool
restore textures.
-
Update the map as each frame is rendered.
Declaration
Swift
public func update(_ currentTime: TimeInterval)
Parameters
currentTime
TimeInterval
update interval. -
Initialize the grid graph with an array of walkable tiles.
Declaration
Swift
public func gridGraphForLayers(_ layers: [SKTileLayer], walkable: [SKTile], obstacle: [SKTile] = [], diagonalsAllowed: Bool = false, nodeClass: String? = nil)
Parameters
layers
[SKTileLayer]
array of tile layers.walkable
[SKTile]
array of walkable tiles.obstacles
[SKTile]
array of obstacle tiles.diagonalsAllowed
Bool
allow diagonal movement in the grid.nodeClass
String?
graph node type.
-
Parse properties from the Tiled TMX file.
Declaration
Swift
public func parseProperties(completion: (() -> Void)?)
Parameters
completion
Void?
optional completion closure.
-
Auto-sizing property for map orientation.
Declaration
Swift
public var isPortrait: Bool { get }
-
Current tile width value.
Declaration
Swift
public var tileWidth: CGFloat { get }
-
Current tile height value.
Declaration
Swift
public var tileHeight: CGFloat { get }
-
▶︎graphs
Returns all pathfinding graphs in the map
Declaration
Swift
public var graphs: [GKGridGraph<GKGridGraphNode>] { get }
-
String representation of the map.
Declaration
Swift
override public var description: String { get }
-
Debug string representation of the map.
Declaration
Swift
override public var debugDescription: String { get }
-
Returns an array of tiles/objects.
Declaration
Swift
public func renderableObjects() -> [SKNode]
Return Value
[SKNode]
array of child objects. -
Return tiles & objects at the given point in the map.
Declaration
Swift
public func renderableObjectsAt(point: CGPoint) -> [SKNode]
Parameters
point
CGPoint
position in tilemap.Return Value
[SKNode]
array of tiles. -
Returns an array of animated tiles/objects.
Declaration
Swift
public func animatedObjects() -> [SKNode]
Return Value
[SKNode]
array of child objects.
-
Load a Tiled tmx file and return a new
SKTilemap
object. Returns nil if there is a problem reading the fileDeclaration
Swift
@available(*, deprecated, renamed: "SKTilemap.load(tmxFile:﹚") public class func load(fromFile filename: String, delegate: SKTilemapDelegate? = nil, withTilesets: [SKTileset]? = nil) -> SKTilemap?
Parameters
filename
String
Tiled file name.delegate
SKTilemapDelegate?
optionalSKTilemapDelegate
instance.Return Value
SKTilemap?
tilemap object (if file read succeeds). -
Returns an array of all child layers, sorted by index (first is lowest, last is highest).
Declaration
Swift
@available(*, deprecated, message: "use `getLayers(﹚` instead") public func allLayers() -> [SKTiledLayerObject]
Return Value
[SKTiledLayerObject]
array of layers. -
Returns a named tile layer from the layers set.
Declaration
Swift
@available(*, deprecated, message: "use `getLayers(named:﹚` instead") public func getLayer(named layerName: String) -> SKTiledLayerObject?
Parameters
name
String
tile layer name.Return Value
SKTiledLayerObject?
layer object. -
Returns a named tile layer if it exists, otherwise, nil.
Declaration
Swift
@available(*, deprecated, message: "use `tileLayers(named:﹚` instead") public func tileLayer(named name: String) -> SKTileLayer?
Parameters
named
String
tile layer name.Return Value
SKTileLayer?
-
Returns a named object group if it exists, otherwise, nil.
Declaration
Swift
@available(*, deprecated, message: "use `objectGroups(named:﹚` instead") public func objectGroup(named name: String) -> SKObjectGroup?
Parameters
named
String
tile layer name.Return Value
SKObjectGroup?
-
Output a summary of the current scenes layer data.
Declaration
Swift
@available(*, deprecated, message: "use `dumpStatistics` instead") public func debugLayers(reverse: Bool = false)
Parameters
reverse
Bool
reverse layer order. -
▶︎minZoom
Minimum zoom level for the map.
Declaration
Swift
@available(*, deprecated, renamed: "SKTilemap.zoomConstraints.min") public var minZoom: CGFloat { get set }
-
▶︎maxZoom
Maximum zoom level for the map.
Declaration
Swift
@available(*, deprecated, renamed: "SKTilemap.zoomConstraints.max") public var maxZoom: CGFloat { get set }