SKTilemap

public class SKTilemap : SKNode, CustomReflectable, TiledMappableGeometryType, TiledObjectType

The SKTilemap class is a mappable 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

  • mapSize: Size of the map (in tiles).
  • tileSize: Map tile size (in pixels).
  • sizeInPoints: Size of the map in pixels.
  • orientation: Map orientation (orthogonal, isometric, etc).
  • boundingRect: Map bounding rect.
  • tilesets: Array of stored tileset instances.
  • allowZoom: Allow camera zooming.
  • layers: Array of child layers.

For more information, see the Working with Maps page in the official documentation.

File Properties

  • url

    Tilemap source file path.

    Declaration

    Swift

    public internal(set) var url: URL! { get }
  • Tilemap source file path, relative to the bundle.

    Declaration

    Swift

    public internal(set) var relativeUrl: URL! { get }
  • Map container display name. Defaults to the current map source file name (minus the tmx extension).

    Declaration

    Swift

    public var displayName: String?

Tilesets

Basic Properties

Layers

Background Properties

Positioning

  • Mappable child node offset. By default, the SKTilemap node aligns child layers to its’ center point.

    Used when a map container aligns all of the layers.

    Declaration

    Swift

    public var childOffset: CGPoint { get }
  • Defines this map’s position within a Tiled world. This value cannot be changed directly, but matches the value set in the world JSON description.

    Declaration

    Swift

    public internal(set) var worldOffset: CGPoint { get }
  • The map projection type.

    Declaration

    Swift

    public internal(set) var orientation: TilemapOrientation { get }

Camera

Hexagonal/Staggered Properties

Content Root Nodes

  • Setting this property masks the map at its boundaries.

    Declaration

    Swift

    public var isCropped: Bool { get set }
  • This object’s CGPath defining the shape of geometry. Used to draw the bounding shape.

    Declaration

    Swift

    @objc
    public lazy var objectPath: CGPath { get set }

Misc Properties

  • Signifies that the tilemap is fully initialized.

    Declaration

    Swift

    public private(set) var isInitialized: Bool { get }

Tile Update Mode

  • Update mode used for tiles & objects.

    Constants

    • dynamic: dynamically update tiles as needed.
    • full: all tiles are updated each frame.
    • actions: tiles are not updated, SpriteKit actions are used instead.

    Declaration

    Swift

    public var updateMode: TileUpdateMode { get set }

Render Quality

Content Root

  • Tilemap custom shader.

    Declaration

    Swift

    public var shader: SKShader? { get set }
  • A Boolean value that determines whether the tilemap node applies the filter to its child layers as they are drawn.

    If the value of this property is true, the effect node applies the filter and blends the results. If the value is false, the effect node is ignored and its children are rendered normally. The default value is false.

    Declaration

    Swift

    public var shouldEnableEffects: Bool { get set }
  • Indicates whether the results of rendering the child nodes should be cached.

    Declaration

    Swift

    public var shouldRasterize: Bool { get set }
  • Image processing filter.

    Declaration

    Swift

    public var filter: CIFilter? { get set }
  • Speed modifier applied to all actions executed by the tilemap and its descendants.

    Declaration

    Swift

    public override var speed: CGFloat { get set }

Debug Overlay

Debugging

Color Attributes

  • Color used to display object frames.

    Declaration

    Swift

    public var objectColor: SKColor
  • Default color (used for pause).

    Declaration

    Swift

    public var color: SKColor
  • Color used to visualize the tile grid.

    Declaration

    Swift

    public var gridColor: SKColor
  • Bounding frame color.

    Declaration

    Swift

    public var frameColor: SKColor
  • Color used to highlight tiles.

    Declaration

    Swift

    public var highlightColor: SKColor
  • Navigation graph color.

    Declaration

    Swift

    public var navigationColor: SKColor
  • Gravity vector.

    Declaration

    Swift

    public var gravity: CGVector
  • Map frame in parent coordinate space.

    Declaration

    Swift

    public override var frame: CGRect { get }
  • Returns a bounding rect for the entire map. Adapted from Tiled Renderer.mapBoundingRect.

    Declaration

    Swift

    public override var boundingRect: CGRect { get }
  • The accumulated map size.

    Declaration

    Swift

    public var absoluteSize: CGSize { get }
  • Returns the last GID for all of the tilesets.

    Declaration

    Swift

    public var lastGID: UInt32 { get }
  • Returns the last index for all tilesets.

    Declaration

    Swift

    public var lastIndex: UInt32 { 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 }
  • Return all tile layers. If recursive is false, only returns top-level layers.

    Declaration

    Swift

    public func tileLayers(recursive: Bool = true) -> [SKTileLayer]

    Parameters

    recursive

    include nested layers.

    Return Value

    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

    include nested layers.

    Return Value

    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

    include nested layers.

    Return Value

    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

    include nested layers.

    Return Value

    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 }
  • A Boolean value that determines whether actions on the node and its descendants are processed.

    Pauses the tilemap, and colors all of its children darker via the overlay.

    Declaration

    Swift

    public override var isPaused: Bool { get set }

Loading

  • 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

    Tiled file name.

    Return Value

    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

    Tiled file name.

    completion

    optional completion block.

    Return Value

    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

    Tiled file name.

    loggingLevel

    logging verbosity level.

    Return Value

    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: TilemapDelegate) -> SKTilemap?

    Parameters

    tmxFile

    Tiled file name.

    delegate

    tilemap delegate instance.

    Return Value

    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: TilemapDelegate,
                           updateMode: TileUpdateMode) -> SKTilemap?

    Parameters

    tmxFile

    Tiled file name.

    delegate

    tilemap delegate instance.

    updateMode

    tile update mode.

    Return Value

    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: TilemapDelegate,
                           tilesetDataSource: TilesetDataSource) -> SKTilemap?

    Parameters

    tmxFile

    Tiled file name.

    delegate

    tilemap delegate instance.

    tilesetDataSource

    tilemap TilesetDataSource instance.

    Return Value

    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: TilemapDelegate,
                           tilesetDataSource: TilesetDataSource,
                           updateMode: TileUpdateMode) -> SKTilemap?

    Parameters

    tmxFile

    Tiled file name.

    delegate

    tilemap delegate instance.

    tilesetDataSource

    tilemap TilesetDataSource instance.

    updateMode

    tile update mode.

    Return Value

    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: TilemapDelegate,
                           tilesetDataSource: TilesetDataSource,
                           withTilesets: [SKTileset]) -> SKTilemap?

    Parameters

    tmxFile

    Tiled file name.

    delegate

    tilemap delegate instance.

    tilesetDataSource

    tilemap TilesetDataSource instance.

    withTilesets

    pre-loaded tilesets.

    Return Value

    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. This is the primary loading method for tilemaps. Currently used by the demo app.

    Declaration

    Swift

    public class func load(tmxFile: String,
                           inDirectory: String? = nil,
                           delegate: TilemapDelegate? = nil,
                           tilesetDataSource: TilesetDataSource? = 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

    Tiled file name.

    inDirectory

    asset search path.

    delegate

    optional TilemapDelegate instance.

    tilesetDataSource

    optional TilesetDataSource instance.

    updateMode

    tile update mode.

    withTilesets

    pre-loaded tilesets.

    noparse

    ignore custom properties from Tiled.

    loggingLevel

    logging verbosity level.

    completion

    optional completion block.

    Return Value

    tilemap object (if file read succeeds).

String Loading

Initialization

  • Instantiate the map with a decoder instance.

    Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)

    Parameters

    aDecoder

    decoder.

  • Initialize with dictionary attributes from Tiled source XML.

    Declaration

    Swift

    public init?(attributes: [String : String])

    Parameters

    attributes

    attributes parsed from Tiled XML.

  • Initialize with map size/tile size.

    Declaration

    Swift

    public init(_ sizeX: Int, _ sizeY: Int,
                _ tileSizeX: Int, _ tileSizeY: Int,
                orientation: TilemapOrientation = .orthogonal)

    Parameters

    sizeX

    map width in tiles.

    sizeY

    map height in tiles.

    tileSizeX

    tile width in pixels.

    tileSizeY

    tile height in pixels.

    orientation

    map orientation.

Tileset Mangement

  • Add a tileset to tilesets set.

    Declaration

    Swift

    public func addTileset(_ tileset: SKTileset)

    Parameters

    tileset

    tileset object.

  • Remove a tileset from the tilesets set.

    Declaration

    Swift

    public func removeTileset(_ tileset: SKTileset) -> SKTileset?

    Parameters

    tileset

    tileset object.

    Return Value

    removed tileset.

  • Returns a named tileset from the tilesets set.

    Declaration

    Swift

    public func getTileset(named: String) -> SKTileset?

    Parameters

    named

    tileset to return.

    Return Value

    tileset object.

  • Returns an externally referenced tileset with a given filename.

    Declaration

    Swift

    public func getTileset(fileNamed filename: String) -> SKTileset?

    Parameters

    filename

    tileset source file.

    Return Value

    tileset with the given file name.

  • Returns the tileset associated with a global id.

    Declaration

    Swift

    public func getTilesetFor(globalID: UInt32) -> SKTileset?

    Parameters

    globalID

    tile global id.

    Return Value

    associated tileset.

  • Returns the tileset containing the given global id.

    Declaration

    Swift

    public func contains(globalID: UInt32) -> (Bool, SKTileset?)

    Parameters

    globalID

    tile global id.

    Return Value

    tuple of result & matching tileset.

Layer Management

  • Returns an array of child layers, sorted by index (first is lowest, last is highest).

    Declaration

    Swift

    public func getLayers(recursive: Bool = true) -> [TiledLayerObject]

    Parameters

    recursive

    include nested layers.

    Return Value

    array of layers.

  • Return child layers matching the given name.

    Declaration

    Swift

    public func getLayers(named layerName: String, recursive: Bool = true) -> [TiledLayerObject]

    Parameters

    layerName

    tile layer name.

    recursive

    include nested layers.

    Return Value

    layer objects.

  • Return child layers with names matching the given prefix.

    Declaration

    Swift

    public func getLayers(withPrefix: String, recursive: Bool = true) -> [TiledLayerObject]

    Parameters

    withPrefix

    prefix to match.

    recursive

    include nested layers.

    Return Value

    layer objects.

  • Return child layers with matching the given path. Tiled allows for duplicate layer names, so we’re returning an array.

    Declaration

    Swift

    public func getLayers(atPath: String) -> [TiledLayerObject]

    Parameters

    withPrefix

    layer path to search for.

    Return Value

    layer objects.

  • Returns a child layer given an xPath value.

    Declaration

    Swift

    public func getLayer(xPath: String) -> TiledLayerObject?

    Parameters

    xPath

    layer xPath.

    Return Value

    layer objects.

  • Returns a child layer matching the given UUID.

    Declaration

    Swift

    public func getLayer(withID uuid: String) -> TiledLayerObject?

    Parameters

    uuid

    tile layer UUID.

    Return Value

    layer object.

  • Returns a child layer given the index (0 being the lowest).

    Declaration

    Swift

    public func getLayer(atIndex index: UInt32) -> TiledLayerObject?

    Parameters

    index

    layer index.

    Return Value

    layer object.

  • Returns child layers assigned a custom type property.

    Declaration

    Swift

    public func getLayers(ofType: String, recursive: Bool = true) -> [TiledLayerObject]

    Parameters

    ofType

    layer type.

    recursive

    include nested layers.

    Return Value

    array of layers.

  • Returns all content layers (ie. not groups). Sorted by zPosition in scene.

    Declaration

    Swift

    public func getContentLayers() -> [TiledLayerObject]

    Return Value

    array of layers.

  • Returns an array of layer names.

    Declaration

    Swift

    public func layerNames() -> [String]

    Return Value

    layer names.

  • Add a layer to the current layers set. Automatically sets zPosition based on the SKTilemap.zDeltaForLayers property. If the group argument is not nil, layer will be added to the group instead.

    Declaration

    Swift

    @discardableResult
    public func addLayer(_ layer: TiledLayerObject,
                         group: SKGroupLayer? = nil,
                         clamped: Bool = true) -> (success: Bool, layer: TiledLayerObject)

    Parameters

    layer

    layer object.

    group

    optional group layer.

    clamped

    clamp position to nearest pixel.

    Return Value

    add was successful, added layer.

  • Remove a layer from the current layers set.

    Declaration

    Swift

    public func removeLayer(_ layer: TiledLayerObject) -> TiledLayerObject?

    Parameters

    layer

    layer object.

    Return Value

    removed layer.

  • Create and add a new tile layer. By default, the new layer will be parented to the tilemap instance unless an optional group layer is specified.

    Declaration

    Swift

    @discardableResult
    public func newTileLayer(named: String, group: SKGroupLayer? = nil) -> SKTileLayer

    Parameters

    named

    layer name.

    group

    optional group layer.

    Return Value

    new layer.

  • Create and add a new tile layer with optional layer data. By default, the new layer will be parented to the tilemap instance unless an optional group layer is specified.

    Declaration

    Swift

    @discardableResult
    public func newTileLayer(named: String,
                             group: SKGroupLayer? = nil,
                             data: [UInt32] = []) -> SKTileLayer

    Parameters

    named

    layer name.

    group

    optional group layer.

    data

    array of tile global ids.

    Return Value

    new tile layer.

  • Create and add a new object group. By default, the new layer will be parented to the tilemap instance unless an optional group layer is specified.

    Declaration

    Swift

    @discardableResult
    public func newObjectGroup(named: String, group: SKGroupLayer? = nil) -> SKObjectGroup

    Parameters

    named

    layer name.

    group

    optional group layer.

    Return Value

    new layer.

  • Create and add a new image layer. By default, the new layer will be parented to the tilemap instance unless an optional group layer is specified.

    Declaration

    Swift

    @discardableResult
    public func newImageLayer(named: String, group: SKGroupLayer? = nil) -> SKImageLayer

    Parameters

    named

    layer name.

    group

    optional group layer.

    Return Value

    new layer.

  • Create and add a new group layer. By default, the new layer will be parented to the tilemap instance unless an optional group layer is specified.

    Declaration

    Swift

    @discardableResult
    public func newGroupLayer(named: String, group: SKGroupLayer? = nil) -> SKGroupLayer

    Parameters

    named

    layer name.

    group

    optional group layer.

    Return Value

    new layer.

  • 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

    layerName

    tile layer name.

    recursive

    include nested layers.

    Return Value

    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

    prefix to match.

    recursive

    include nested layers.

    Return Value

    array of tile layers.

  • Returns a tile layer at the given index, otherwise, nil.

    Declaration

    Swift

    public func tileLayer(atIndex index: Int) -> SKTileLayer?

    Parameters

    index

    layer index.

    Return Value

    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

    layerName

    tile layer name.

    recursive

    include nested layers.

    Return Value

    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

    prefix to match.

    recursive

    include nested layers.

    Return Value

    array of object groups.

  • Returns an object group at the given index, otherwise, nil.

    Declaration

    Swift

    public func objectGroup(atIndex index: Int) -> SKObjectGroup?

    Parameters

    index

    layer index.

    Return Value

    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

    layerName

    tile layer name.

    recursive

    include nested layers.

    Return Value

    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

    prefix to match.

    recursive

    include nested layers.

    Return Value

    array of image layers.

  • Returns an image layer at the given index, otherwise, nil.

    Declaration

    Swift

    public func imageLayer(atIndex index: Int) -> SKImageLayer?

    Parameters

    index

    layer index.

    Return Value

    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

    layerName

    tile layer name.

    recursive

    include nested layers.

    Return Value

    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

    prefix to match.

    recursive

    include nested layers.

    Return Value

    array of group layers.

  • Returns an group layer at the given index, otherwise, nil.

    Declaration

    Swift

    public func groupLayer(atIndex index: Int) -> SKGroupLayer?

    Parameters

    index

    layer index.

    Return Value

    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

    optional starting z-position.

  • Returns an array of tile & object layers.

    Declaration

    Swift

    public func contentLayers() -> [TiledLayerObject]

    Return Value

    tile & vector object layers.

Tiles

  • Return tiles at the given coordinate (all tile layers).

    Declaration

    Swift

    public func tilesAt(coord: simd_int2) -> [SKTile]

    Parameters

    coord

    coordinate.

    Return Value

    array of tiles.

  • Return tiles at the given coordinate (all tile layers).

    Declaration

    Swift

    public func tilesAt(_ x: Int, _ y: Int) -> [SKTile]

    Parameters

    x

    x-coordinate.

    y

    y-coordinate.

    Return Value

    array of tiles.

  • Returns the first tile at the given coordinate from a layer.

    Declaration

    Swift

    public func tileAt(coord: simd_int2, inLayer named: String?) -> SKTile?

    Parameters

    coord

    tile coordinate.

    named

    layer name.

    Return Value

    matching tile, if one exists.

  • 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

    tile x-coordinate.

    y

    tile y-coordinate

    named

    layer name.

    Return Value

    matching tile, if one exists.

  • Return the top-most tile at the given coordinate.

    Declaration

    Swift

    public func firstTileAt(coord: simd_int2) -> SKTile?

    Parameters

    coord

    coordinate.

    Return Value

    first tile in layers.

  • 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

    include nested layers.

    Return Value

    array of tiles.

  • Returns an array of 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

    tile type.

    recursive

    include nested layers.

    Return Value

    array of tiles.

  • Returns an array of tiles matching the given global id. If recursive is false, only returns tiles from top-level layers.

    Declaration

    Swift

    public func getTiles(globalID: UInt32, recursive: Bool = true) -> [SKTile]

    Parameters

    globalID

    tile global id.

    recursive

    include nested layers.

    Return Value

    array of tiles.

  • Returns tiles with a property matching the given name.

    Declaration

    Swift

    public func getTilesWithProperty(_ named: String, recursive: Bool = true) -> [SKTile]

    Parameters

    named

    property name.

    recursive

    include nested layers.

    Return Value

    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

    property name.

    value

    property value.

    recursive

    include nested layers

    Return Value

    array of tiles.

  • Returns an array of all animated tile objects.

    Declaration

    Swift

    public func animatedTiles(recursive: Bool = true) -> [SKTile]

    Parameters

    recursive

    include nested layers.

    Return Value

    array of tiles

  • Creates and returns a new tile instance with the given global id.

    Declaration

    Swift

    public func newTile(globalID: UInt32, type tileType: SKTile.Type = SKTile.self) -> SKTile?

    Parameters

    localID

    tile gobal id.

    tileType

    tile object type.

    Return Value

    tile instance, if tile data exists.

Tile Data

  • Returns tile data for a global tile id.

    Declaration

    Swift

    public func getTileData(globalID: UInt32) -> SKTilesetData?

    Parameters

    globalID

    global tile id.

    Return Value

    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

    tile data type.

    Return Value

    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

    property name.

    Return Value

    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

    property name.

    value

    property value.

    Return Value

    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

    name

    data name.

    isAnimated

    filter data that is animated.

    Return Value

    array of tile data.

Objects

  • Return objects at the given point (all object groups).

    Declaration

    Swift

    public func objectsAt(point: CGPoint) -> [SKTileObject]

    Parameters

    point

    coordinate.

    Return Value

    array of objects.

  • Return objects at the given coordinate (all object groups). Queries the TileObjectOverlay node, which is not exposed to the public API.

    Declaration

    Swift

    public func objectsAt(coord: CGPoint) -> [SKTileObject]

    Parameters

    coord

    coordinate.

    Return Value

    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

    include nested layers.

    Return Value

    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

    object type to query.

    recursive

    include nested layers.

    Return Value

    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

    object name to query.

    recursive

    include nested layers.

    Return Value

    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

    text

    text value.

    recursive

    include nested layers.

    Return Value

    array of matching objects.

  • Returns an object with the given Tiled id.

    Declaration

    Swift

    public func getObject(withID id: UInt32) -> SKTileObject?

    Parameters

    id

    Object id.

    Return Value

    object matching the given id.

  • 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

    include nested layers.

    Return Value

    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: UInt32, recursive: Bool = true) -> [SKTileObject]

    Parameters

    globalID

    global tile id.

    recursive

    include nested layers.

    Return Value

    array of objects matching the given tile global id.

  • 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

    include nested layers.

    Return Value

    text objects.

Physics

Coordinates

  • Returns true if the coordinate is valid (within map bounds).

    Declaration

    Swift

    public func isValid(_ x: Int32, _ y: Int32) -> Bool

    Parameters

    x

    x-coordinate.

    y

    y-coordinate.

    Return Value

    coordinate is valid.

  • Returns true if the coordinate is valid (within map bounds).

    Declaration

    Swift

    public func isValid(coord: simd_int2) -> Bool

    Parameters

    coord

    tile coordinate.

    Return Value

    coordinate 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

    event

    mouse event.

    Return Value

    converted point in map coordinate system.

  • Returns the tile coordinate at a mouse event location.

    Declaration

    Swift

    public func coordinateAtMouse(event: NSEvent) -> simd_int2

    Parameters

    event

    mouse event.

    Return Value

    converted point in layer coordinate system.

Shaders

  • Set a shader for the map.

    Declaration

    Swift

    public func setShader(named: String, uniforms: [SKUniform] = [], attributes: [SKAttribute] = [])

    Parameters

    named

    shader file name.

    uniforms

    array of shader uniforms.

    attributes

    array of shader attributes.

Callbacks

SpriteKit Actions

  • Toggle tilemap animation rendering as SpriteKit actions.

    Declaration

    Swift

    public func runAnimationAsActions(_ value: Bool, restore: Bool = true)

    Parameters

    value

    on/off toggle.

    restore

    restore textures.

Updating

  • Updates the tilemap as each frame is rendered.

    Declaration

    Swift

    public func update(_ currentTime: TimeInterval)

    Parameters

    currentTime

    update interval.

Reflection

SKTilemap

  • Parse properties from the Tiled TMX file.

    Declaration

    Swift

    public func parseProperties(completion: (() -> Void)?)

    Parameters

    completion

    optional completion closure.

Extensions

  • String representing the map name (ie: dungeon-16x16).

    Defaults to the current map source file name (minus the tmx extension).

    Declaration

    Swift

    public var mapName: String { get }
  • Auto-sizing property for map orientation.

    Declaration

    Swift

    public var isPortrait: Bool { get }
  • Returns the width (in tiles) of the map.

    Declaration

    Swift

    public var width: CGFloat { get }
  • Returns the height (in tiles) of the map.

    Declaration

    Swift

    public var height: CGFloat { get }
  • Returns the tile width (in pixels) value.

    Declaration

    Swift

    public var tileWidth: CGFloat { get }
  • Returns the tile size height (in pixels).

    Declaration

    Swift

    public var tileHeight: CGFloat { get }

    Return Value

    tile size height.

  • Returns the tile size width (in pixels), halved.

    Declaration

    Swift

    public var tileWidthHalf: CGFloat { get }

    Return Value

    tile size half-width.

  • Returns the tile size height (in pixels), halved.

    Declaration

    Swift

    public var tileHeightHalf: CGFloat { get }

    Return Value

    tile size half-height.

  • Returns the container size (in tiles), halved.

    Declaration

    Swift

    public var sizeHalved: CGSize { get }

    Return Value

    container size in tiles, halved.

  • Returns the container tile size (in pixels), halved.

    Declaration

    Swift

    public var tileSizeHalved: CGSize { get }

    Return Value

    container tile size in tiles, halved.

  • Returns all pathfinding graphs in the map.

    Declaration

    Swift

    public var graphs: [GKGridGraph<GKGridGraphNode>] { get }
  • Returns an array of renderable tiles/objects.

    Declaration

    Swift

    public func renderableObjects() -> [SKNode]

    Return Value

    array of child objects.

  • Returns an array of animated tiles/objects.

    Declaration

    Swift

    public func animatedObjects() -> [SKNode]

    Return Value

    array of child objects.

  • Highlight the map with a given color & duration.

    Declaration

    Swift

    @objc
    public override func highlightNode(with color: SKColor, duration: TimeInterval = 0)

    Parameters

    color

    highlight color.

    duration

    duration of highlight effect.

  • Remove the current object’s highlight color.

    Declaration

    Swift

    @objc
    public override func removeHighlight()

Deprecations

  • Container size (in tiles).

    Declaration

    Swift

    @available(*, deprecated, renamed: "mapSize")
    public internal(set) var size: CGSize { get set }
  • Load a Tiled tmx file and return a new SKTilemap object. Returns nil if there is a problem reading the file.

    Declaration

    Swift

    @available(*, deprecated, renamed: "SKTilemap.load(tmxFile:﹚")
    public class func load(fromFile filename: String,
                           delegate: TilemapDelegate? = nil,
                           withTilesets: [SKTileset]? = nil) -> SKTilemap?

    Parameters

    filename

    Tiled file name.

    delegate

    optional TilemapDelegate instance.

    withTilesets

    optional tilesets.

    Return Value

    tilemap object.

  • 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() -> [TiledLayerObject]

    Return Value

    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) -> TiledLayerObject?

    Parameters

    layerName

    tile layer name.

    Return Value

    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

    name

    tile layer name.

    Return Value

    matching tile layer.

  • 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

    name

    tile layer name.

    Return Value

    object layer matching the given name, if one exists.

  • 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

    reverse layer order.

  • Minimum zoom level for the map.

    Declaration

    Swift

    @available(*, deprecated, renamed: "zoomConstraints.min")
    public var minZoom: CGFloat { get set }
  • Maximum zoom level for the map.

    Declaration

    Swift

    @available(*, deprecated, renamed: "zoomConstraints.max")
    public var maxZoom: CGFloat { get set }
  • Returns the render time of this map.

    Declaration

    Swift

    @available(*, deprecated, renamed: "renderTime")
    public var mapRenderTime: TimeInterval { get }
  • Returnas true if any of the child layers is showing a graph visual.

    Declaration

    Swift

    @available(*, deprecated, renamed: "isShowingGridGraph")
    public var isShowingGraphs: Bool { get }
  • Show objects for the given layers.

    Declaration

    Swift

    @available(*, deprecated, message: "use `debugDrawOptions` instead")
    public func showObjects(forLayers: [TiledLayerObject])

    Parameters

    forLayers

    array of layers.

  • Returns the tileset associated with a global id.

    Declaration

    Swift

    @available(*, deprecated, renamed: "getTilesetFor(globalID:﹚")
    public func getTileset(forTile: Int) -> SKTileset?

    Parameters

    forTile

    tile global id.

    Return Value

    associated tileset.

  • Returns an object with the given Tiled id.

    Declaration

    Swift

    @available(*, deprecated, renamed: "getObject(withID:﹚")
    public func getObject(withID id: Int) -> SKTileObject?

    Parameters

    id

    Object id.

    Return Value

    object matching the given id.

  • Return objects with a tile id. If recursive is false, only returns objects from top-level layers.

    Declaration

    Swift

    @available(*, deprecated, renamed: "tileObjects(globalID:recursive:﹚")
    public func tileObjects(globalID: Int, recursive: Bool = true) -> [SKTileObject]

    Parameters

    globalID

    global tile id.

    recursive

    include nested layers.

    Return Value

    array of objects matching the given tile global id.

  • Returns tiles with the given global id. If recursive is false, only returns tiles from top-level layers.

    Declaration

    Swift

    @available(*, deprecated, renamed: "getTiles(globalID:recursive:﹚")
    public func getTiles(globalID: Int, recursive: Bool = true) -> [SKTile]

    Parameters

    globalID

    tile global id.

    recursive

    include nested layers.

    Return Value

    array of tiles.

  • Returns true if the coordinate is valid.

    Declaration

    Swift

    @available(*, deprecated, renamed: "isValid(coord:﹚")
    public func isValid(coord: CGPoint) -> Bool

    Parameters

    coord

    tile coordinate.

    Return Value

    coordinate is valid.

  • Return tiles at the given point (all tile layers).

    Declaration

    Swift

    @available(*, deprecated, message: "???")
    public func tilesAt(point: CGPoint) -> [SKTile]

    Parameters

    point

    position in tilemap.

    Return Value

    array of tiles.

  • Return tiles at the given coordinate (all tile layers).

    Declaration

    Swift

    @available(*, deprecated, renamed: "tilesAt(coord:﹚")
    public func tilesAt(coord: CGPoint) -> [SKTile]

    Parameters

    coord

    coordinate.

    Return Value

    array of tiles.

  • Returns the first tile at the given coordinate from a layer.

    Declaration

    Swift

    @available(*, deprecated, renamed: "tileAt(coord:simd_int2:inLayer:﹚")
    public func tileAt(coord: CGPoint, inLayer named: String?) -> SKTile?

    Parameters

    coord

    tile coordinate.

    named

    layer name.

    Return Value

    matching tile, if one exists.

  • Return the top-most tile at the given coordinate.

    Declaration

    Swift

    @available(*, deprecated, renamed: "firstTileAt(coord:﹚")
    public func firstTileAt(coord: CGPoint) -> SKTile?

    Parameters

    coord

    coordinate.

    Return Value

    first tile in layers.

  • Returns a tile coordinate for a given simd_int2 coordinate.

    Declaration

    Swift

    @available(*, deprecated, renamed: "pointForCoordinate(coord:﹚")
    public func pointForCoordinate(vec2: simd_int2) -> CGPoint

    Parameters

    vec2

    simd_int2 coordinate

    Return Value

    position in map.

  • Returns a tile coordinate for a given point in the layer.

    Declaration

    Swift

    @available(*, deprecated, renamed: "coordinateForPoint(point:﹚")
    public func coordinateForPoint(_ point: CGPoint) -> CGPoint

    Parameters

    point

    point in layer.

    Return Value

    tile coordinate.

  • Returns a tile coordinate for a given point in the layer as a simd_int2.

    Declaration

    Swift

    @available(*, deprecated, message: "use coordinateForPoint(point:﹚")
    public func vectorCoordinateForPoint(_ point: CGPoint) -> simd_int2

    Parameters

    point

    point in layer.

    Return Value

    tile coordinate

  • Returns the tile coordinate at a mouse event location.

    Declaration

    Swift

    @available(*, deprecated, renamed: "coordinateAtMouse(event:﹚")
    public func coordinateAtMouseEvent(event: NSEvent) -> CGPoint

    Parameters

    event

    mouse event.

    Return Value

    converted point in layer coordinate system.

  • Returns a layer given the index (0 being the lowest).

    Declaration

    Swift

    @available(*, deprecated, renamed: "getLayer(atIndex:﹚")
    public func getLayer(atIndex index: Int) -> TiledLayerObject?

    Parameters

    index

    layer index.

    Return Value

    layer object.

  • Global property to show/hide all SKTileObject objects.

    Declaration

    Swift

    @available(*, deprecated, renamed: "isShowingObjectBounds")
    public var showObjects: Bool { get set }