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
See moreProperty 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
-
▶︎urlTilemap source file path.
Declaration
Swift
public var url: URL! -
▶︎uuidUnique 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 } -
▶︎typeTilemap 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 } -
▶︎sizeSize of map (in tiles).
Declaration
Swift
public var size: CGSize -
▶︎tileSizeTile 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? -
▶︎mapNameString 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 } -
▶︎speedMap 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 } -
▶︎boundsMap 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
-
▶︎firstGIDFirst global id value.
Declaration
Swift
public var firstGID: Int -
▶︎tilesetsCurrent 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
-
▶︎layersReturns 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
-
▶︎gravitydynamics
Declaration
Swift
public var gravity: CGVector -
▶︎delegateReference to
SKTilemapDelegatedelegate.Declaration
Swift
weak public var delegate: SKTilemapDelegate? -
▶︎frameMap 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 } -
▶︎lastGIDReturns 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
SKTileObjectobjects.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
recursiveBoolinclude 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
recursiveBoolinclude 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
recursiveBoolinclude 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
recursiveBoolinclude 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 } -
▶︎isPausedPauses 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
SKTilemapobject. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String) -> SKTilemap?Parameters
tmxFileStringTiled file name.Return Value
SKTilemap?tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemapobject. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, _ completion: ((_ tilemap: SKTilemap) -> Void)? = nil) -> SKTilemap?Parameters
tmxFileStringTiled 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
SKTilemapobject. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, loggingLevel: LoggingLevel) -> SKTilemap?Parameters
tmxFileStringTiled file name.loggingLevelLoggingLevellogging verbosity level.Return Value
SKTilemap?tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemapobject. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate) -> SKTilemap?Parameters
tmxFileStringTiled file name.delegateSKTilemapDelegatetilemap delegate instance.Return Value
SKTilemap?tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemapobject. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate, updateMode: TileUpdateMode) -> SKTilemap?Parameters
tmxFileStringTiled file name.delegateSKTilemapDelegatetilemap delegate instance.updateModeTileUpdateModetile update mode.Return Value
SKTilemap?tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemapobject. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate, tilesetDataSource: SKTilesetDataSource) -> SKTilemap?Parameters
tmxFileStringTiled file name.delegateSKTilemapDelegatetilemap delegate instance.tilesetDataSourceReturn Value
SKTilemap?tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemapobject. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate, tilesetDataSource: SKTilesetDataSource, updateMode: TileUpdateMode) -> SKTilemap?Parameters
tmxFileStringTiled file name.delegateSKTilemapDelegatetilemap delegate instance.tilesetDataSourceupdateModeTileUpdateModetile update mode.Return Value
SKTilemap?tilemap object (if file read succeeds). -
Load a Tiled tmx file and return a new
SKTilemapobject. Returns nil if there is a parsing error.Declaration
Swift
public class func load(tmxFile: String, delegate: SKTilemapDelegate, tilesetDataSource: SKTilesetDataSource, withTilesets: [SKTileset]) -> SKTilemap?Parameters
tmxFileStringTiled file name.delegateSKTilemapDelegatetilemap delegate instance.tilesetDataSourcewithTilesets[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
SKTilemapobject. 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
tmxFileStringTiled file name.inDirectoryString?search path for assets.delegateSKTilemapDelegate?optionalSKTilemapDelegateinstance.tilesetDataSourceSKTilesetDataSource?optionalSKTilesetDataSourceinstance.updateModeTileUpdateModetile update mode.withTilesets[SKTileset]?optional tilesets.ignorePropertiesBoolignore custom properties from Tiled.loggingLevelLoggingLevellogging 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
attributesDictionaryattributes 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
sizeXIntmap width in tiles.sizeYIntmap height in tiles.tileSizeXInttile width in pixels.tileSizeYInttile height in pixels.Return Value
SKTilemap
-
Remove a tileset from the tilesets set.
Parameters
tilesetSKTilesetremoved tileset. -
Returns a named tileset from the tilesets set.
Declaration
Swift
public func getTileset(named: String) -> SKTileset?Parameters
namedStringtileset 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
filenameStringtileset source file.Return Value
SKTileset? -
Returns the tileset associated with a global id.
Declaration
Swift
public func getTileset(forTile: Int) -> SKTileset?Parameters
forTileInttile 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) -> CGPointParameters
coordCGPointtile coordinate.offsetXCGFloatx-offset value.offsetYCGFloaty-offset value.Return Value
CGPointpoint in layer. -
Returns a tile coordinate for a given vector_int2 coordinate.
Declaration
Swift
public func pointForCoordinate(vec2: int2) -> CGPointParameters
vec2int2vector int2 coordinate.Return Value
CGPointposition in layer. -
Returns a tile coordinate for a given point in the layer.
Declaration
Swift
public func coordinateForPoint(_ point: CGPoint) -> CGPointParameters
pointCGPointpoint in layer.Return Value
CGPointtile coordinate. -
Returns a tile coordinate for a given point in the layer as a vector_int2.
Declaration
Swift
public func vectorCoordinateForPoint(_ point: CGPoint) -> int2Parameters
pointCGPointpoint in layer.Return Value
int2tile 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
recursiveBoolinclude 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.zDeltaForLayersproperty. If thegroupargument 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
layerSKTiledLayerObjectlayer object.groupSKGroupLayer?optional group layer.clampedBoolclamp 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
layerSKTiledLayerObjectlayer object.Return Value
SKTiledLayerObject?removed layer. -
Create and add a new tile layer.
Declaration
Swift
@discardableResult public func newTileLayer(named: String, group: SKGroupLayer? = nil) -> SKTileLayerParameters
namedStringlayer name.groupSKGroupLayer?optional group layer.Return Value
SKTileLayernew layer. -
Create and add a new object group.
Declaration
Swift
@discardableResult public func newObjectGroup(named: String, group: SKGroupLayer? = nil) -> SKObjectGroupParameters
namedStringlayer name.groupSKGroupLayer?optional group layer.Return Value
SKObjectGroupnew layer. -
Create and add a new image layer.
Declaration
Swift
@discardableResult public func newImageLayer(named: String, group: SKGroupLayer? = nil) -> SKImageLayerParameters
namedStringlayer name.groupSKGroupLayer?optional group layer.Return Value
SKImageLayernew layer. -
Create and add a new group layer.
Declaration
Swift
@discardableResult public func newGroupLayer(named: String, group: SKGroupLayer? = nil) -> SKGroupLayerParameters
namedStringlayer name.groupSKGroupLayer?optional group layer.Return Value
SKGroupLayernew layer. -
Return layers matching the given name.
Declaration
Swift
public func getLayers(named layerName: String, recursive: Bool = true) -> [SKTiledLayerObject]Parameters
nameStringtile layer name.recursiveBoolinclude 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
withPrefixStringprefix to match.recursiveBoolinclude nested layers.Return Value
[SKTiledLayerObject]layer objects. -
Return layers at the given path.
Declaration
Swift
public func getLayers(atPath: String) -> [SKTiledLayerObject]Parameters
atPathStringlayer path.Return Value
[SKTiledLayerObject]layer objects. -
Returns a layer matching the given UUID.
Declaration
Swift
public func getLayer(withID uuid: String) -> SKTiledLayerObject?Parameters
uuidStringtile 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
indexIntlayer index.Return Value
SKTiledLayerObject?layer object. -
Return layers assigned a custom
typeproperty.Declaration
Swift
public func getLayers(ofType: String, recursive: Bool = true) -> [SKTiledLayerObject]Parameters
ofTypeStringlayer type.recursiveBoolinclude 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
namedStringtile layer name.recursiveBoolinclude 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
withPrefixStringprefix to match.recursiveBoolinclude 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
atIndexIntlayer 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
namedStringtile layer name.recursiveBoolinclude 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
withPrefixStringprefix to match.recursiveBoolinclude 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
atIndexIntlayer 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
namedStringtile layer name.recursiveBoolinclude 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
withPrefixStringprefix to match.recursiveBoolinclude 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
atIndexIntlayer 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
namedStringtile layer name.recursiveBoolinclude 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
withPrefixStringprefix to match.recursiveBoolinclude 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
atIndexIntlayer 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
fromCGFloat?optional starting z-positon.
-
Return tiles at the given point (all tile layers).
Declaration
Swift
public func tilesAt(point: CGPoint) -> [SKTile]Parameters
pointCGPointposition 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
coordCGPointcoordinate.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
xIntx-coordinate.yInt- 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
coordCGPointtile coordinate.inLayerString?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
xInttile x-coordinate.yInttile y-coordinate.namedString?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
recursiveBoolinclude 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
ofTypeStringtype.recursiveBoolinclude 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
globalIDInttile globla id.recursiveBoolinclude 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
namedStringproperty name.valueAnyproperty value.recursiveBoolinclude 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
coordCGPointcoordinate.Return Value
SKTile?first tile in layers.
-
Returns data for a global tile id.
Declaration
Swift
public func getTileData(globalID gid: Int) -> SKTilesetData?Parameters
globalIDIntglobal tile id.Return Value
SKTilesetDatatile data, if it exists. -
Return tile data with a property of the given type.
Declaration
Swift
public func getTileData(ofType: String) -> [SKTilesetData]Parameters
ofTypeStringtile 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
namedStringproperty 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
namedStringproperty name.valueAnyproperty 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
namedStringdata name.isAnimatedBoolfilter 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
coordCGPointcoordinate.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
recursiveBoolinclude 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
ofTypeStringobject type to query.recursiveBoolinclude 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
namedStringobject name to query.recursiveBoolinclude 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
withTextStringtext value.recursiveBoolinclude 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
idIntObject 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
recursiveBoolinclude 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
globalIDIntglobal tile id.recursiveBoolinclude 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
recursiveBoolinclude nested layers.Return Value
[SKTileObject]text objects.
-
Returns true if the coordinate is valid.
Declaration
Swift
public func isValid(coord: CGPoint) -> BoolParameters
coordCGPointtile coordinate.Return Value
Boolcoodinate 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) -> CGPointParameters
pointCGPointscene point.Return Value
CGPointconverted point in layer coordinate system. -
Returns the tile coordinate at a mouse event location.
Declaration
Swift
public func coordinateAtMouseEvent(event: NSEvent) -> CGPointParameters
eventNSEventmouse event location.Return Value
CGPointconverted point in layer coordinate system.
-
Set a shader for the tile layer.
Declaration
Swift
public func setShader(named: String, uniforms: [SKUniform] = [])Parameters
namedStringshader 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
timeStartedDaterender start time.tasksIntnumber of tasks to complete. -
Called when parser has finished rendering the map.
Declaration
Swift
public func didFinishRendering(timeStarted: Date)Parameters
timeStartedDaterender start time.
-
Run layer animations as SpriteKit actions.
Declaration
Swift
public func runAnimationAsActions(_ value: Bool, restore: Bool = true)Parameters
valueBoolon/off toggle.restoreBoolrestore textures.
-
Update the map as each frame is rendered.
Declaration
Swift
public func update(_ currentTime: TimeInterval)Parameters
currentTimeTimeIntervalupdate 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.diagonalsAllowedBoolallow diagonal movement in the grid.nodeClassString?graph node type.
-
Parse properties from the Tiled TMX file.
Declaration
Swift
public func parseProperties(completion: (() -> Void)?)Parameters
completionVoid?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 } -
▶︎graphsReturns 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
pointCGPointposition 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
SKTilemapobject. 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
filenameStringTiled file name.delegateSKTilemapDelegate?optionalSKTilemapDelegateinstance.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
nameStringtile 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
namedStringtile 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
namedStringtile 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
reverseBoolreverse layer order. -
▶︎minZoomMinimum zoom level for the map.
Declaration
Swift
@available(*, deprecated, renamed: "SKTilemap.zoomConstraints.min") public var minZoom: CGFloat { get set } -
▶︎maxZoomMaximum zoom level for the map.
Declaration
Swift
@available(*, deprecated, renamed: "SKTilemap.zoomConstraints.max") public var maxZoom: CGFloat { get set }
View on GitHub
SKTilemap Class Reference