SKTiledScene
open class SKTiledScene : SKScene, SKPhysicsContactDelegate, TiledSceneDelegate, TilemapDelegate, TilesetDataSource
extension SKTiledScene: TiledSceneCameraDelegate
The SKTiledScene
object represents a scene of content in SpriteKit, customized for including Tiled asset types. This scene type automatically creates camera and world container nodes and sets up interactivity between them and an associated tile map node.
The camera node determines what part of the scene’s coordinate space is visible in the view.
Properties
worldNode
: Root container node.tilemap
: Tile map node.cameraNode
: Custom scene camera.
Instance Methods
cameraPositionChanged
: called when the camera position changes.cameraZoomChanged
: called when the camera zoom changes.cameraBoundsChanged
: called when the camera bounds updated.
Instance Methods (iOS)
sceneDoubleTapped
: Called when the scene receives a double-tap event (iOS only).
Instance Methods (macOS)
sceneClicked
: called when the scene is clicked (macOS only).sceneDoubleClicked
: called when the scene is double-clicked (macOS only).mousePositionChanged
: called when the mouse moves in the scene (macOS only).
See also
For more information, see the Setting Up Your Scenes page in the official documentation.
-
World container node.
Declaration
Swift
open var worldNode: SKNode!
-
Tile map node.
Declaration
Swift
open weak var tilemap: SKTilemap?
-
Custom scene camera.
Declaration
Swift
open weak var cameraNode: SKTiledSceneCamera?
-
Logging verbosity level.
Declaration
Swift
open var loggingLevel: LoggingLevel
-
Reference to navigation graphs.
Declaration
Swift
open var graphs: [String : GKGridGraph<GKGridGraphNode>]
-
Receive notifications from camera.
Declaration
Swift
@objc open var receiveCameraUpdates: Bool
-
Current focus coordinate.
Declaration
Swift
open var currentCoordinate: simd_int2
-
Z-position difference between layers.
Declaration
Swift
open var zDeltaForLayers: CGFloat
-
Speed modifier applied to all actions executed by the scene and its descendants.
Declaration
Swift
open override var speed: CGFloat { get set }
-
Initialize without a tiled map name.
Declaration
Swift
required public override init(size: CGSize)
Parameters
size
scene size
-
Called when the scene is displayed in the parent
SKView
.Declaration
Swift
open override func didMove(to view: SKView)
Parameters
view
parent view.
-
Load and setup a named TMX file, with optional tilesets.
Declaration
Swift
open func setup(url: URL, delegate: TilemapDelegate? = nil, withTilesets: [SKTileset] = [], ignoreProperties: Bool = false, loggingLevel: LoggingLevel = TiledGlobals.default.loggingLevel, _ completion: ((_ tilemap: SKTilemap) -> Void)? = nil)
Parameters
url
Tiled file url.
delegate
optional tilemap delegate instance.
withTilesets
pre-loaded tilesets.
ignoreProperties
don’t parse custom properties.
loggingLevel
logging verbosity.
completion
optional completion handler.
-
Load and setup a named TMX file, with optional tilesets. Allows for an optional completion handler.
Declaration
Swift
open func setup(tmxFile: String, delegate: TilemapDelegate? = nil, inDirectory: String? = nil, withTilesets tilesets: [SKTileset] = [], ignoreProperties: Bool = false, loggingLevel: LoggingLevel = TiledGlobals.default.loggingLevel, _ completion: ((_ tilemap: SKTilemap) -> Void)? = nil)
Parameters
tmxFile
TMX file name.
delegate
optional tilemap delegate instance.
inDirectory
search path for assets.
tilesets
optional pre-loaded tilesets.
ignoreProperties
don’t parse custom properties.
loggingLevel
logging verbosity.
completion
optional completion handler.
-
was size
Declaration
Swift
open func didBeginParsing(_ tilemap: SKTilemap)
-
Declaration
Swift
open func didAddTileset(_ tileset: SKTileset)
-
Declaration
Swift
open func didAddLayer(_ layer: TiledLayerObject)
-
Declaration
Swift
open func didReadMap(_ tilemap: SKTilemap)
-
Declaration
Swift
open func didRenderMap(_ tilemap: SKTilemap)
-
Declaration
Swift
open func didAddNavigationGraph(_ graph: GKGridGraph<GKGridGraphNode>)
-
Declaration
Swift
open func objectForTileType(named: String?) -> SKTile.Type
-
Declaration
Swift
open func objectForVectorType(named: String?) -> SKTileObject.Type
-
Declaration
Swift
open func willAddSpriteSheet(to tileset: SKTileset, fileNamed: String) -> String
-
Called before each frame is rendered.
Declaration
Swift
open override func update(_ currentTime: TimeInterval)
Parameters
currentTime
update interval.
-
Update the camera bounds.
Declaration
Swift
open func updateCamera()
-
Return a custom graph node type.
Declaration
Swift
open func objectForGraphType(named: String?) -> GKGridGraphNode.Type
Parameters
named
graph node type.
Return Value
dictionary insertion was successful.
-
Add a
GKGridGraph
instance to theSKTIledScene.graphs
property. Returns false if that name exists already.Declaration
Swift
open func addGraph(named: String, graph: GKGridGraph<GKGridGraphNode>) -> Bool
Parameters
named
name of graph
graph
graph object.
Return Value
graph was added sucessfully.
-
Remove a named
GKGridGraph
from theSKTIledScene.graphs
property.Declaration
Swift
open func removeGraph(named: String) -> GKGridGraph<GKGridGraphNode>?
Parameters
named
name of graph.
Return Value
removed graph instance.
-
Handler for mouse down events.
Declaration
Swift
open override func mouseDown(with event: NSEvent)
Parameters
event
mouse event.
-
Mouse right-click event handler.
Declaration
Swift
open override func rightMouseDown(with event: NSEvent)
Parameters
event
mouse event.
-
Handler for mouse up events.
Declaration
Swift
open override func mouseUp(with event: NSEvent)
Parameters
event
mouse event.
-
Mouse right-click event handler.
Declaration
Swift
open override func rightMouseUp(with event: NSEvent)
Parameters
event
mouse event.
-
Mouse move event handler.
Declaration
Swift
open override func mouseMoved(with event: NSEvent)
Parameters
event
mouse event.
-
Mouse scroll wheel event handler.
Declaration
Swift
open override func scrollWheel(with event: NSEvent)
Parameters
event
mouse event.
-
Mouse drag event handler.
Declaration
Swift
open override func mouseDragged(with event: NSEvent)
Parameters
event
mouse event.
-
Mouse enter event handler.
Declaration
Swift
open override func mouseEntered(with event: NSEvent)
Parameters
event
mouse event.
-
Mouse exit event handler.
Declaration
Swift
open override func mouseExited(with event: NSEvent)
Parameters
event
mouse event.
-
Called when the scene receives a double-tap event (iOS only).
-
Called when the camera position changes.
Declaration
Swift
@objc open func cameraPositionChanged(newPosition: CGPoint)
Parameters
newPosition
updated camera position.
-
Called when the camera zoom changes.
Declaration
Swift
@objc open func cameraZoomChanged(newZoom: CGFloat)
Parameters
newZoom
camera zoom amount.
-
Called when the camera bounds updated.
Declaration
Swift
@objc open func cameraBoundsChanged(bounds: CGRect, position: CGPoint, zoom: CGFloat)
Parameters
bounds
camera view bounds.
position
camera position.
zoom
camera zoom amount.
-
Called when the scene is clicked (macOS only).
Declaration
Swift
@objc open func leftMouseDown(event: NSEvent)
Parameters
event
mouse click event.
-
Called when the scene is double-clicked (macOS only).
Declaration
Swift
@objc open func leftMouseDoubleClicked(event: NSEvent)
Parameters
event
mouse click event.
-
Called when the scene is right-clicked (macOS only).
Declaration
Swift
@objc open func rightMouseDown(event: NSEvent)
Parameters
event
mouse click event.
-
Called when the right mouse button is released (macOS only).
Declaration
Swift
@objc open func sceneRightClickReleased(event: NSEvent)
Parameters
event
mouse click event.
-
Called when the mouse moves in the scene (macOS only).
Declaration
Swift
@objc open func mousePositionChanged(event: NSEvent)
Parameters
event
mouse move event.
-
Returns a string representation of the node.
Declaration
Swift
open override var description: String { get }
-
Load and setup a named TMX file, with optional tilesets.
Declaration
Swift
@available(*, deprecated, renamed: "setup(url:delegate:withTilesets:ignoreProperties:loggingLevel:_:﹚") open func setup(url: URL, withTilesets: [SKTileset] = [], ignoreProperties: Bool = false, loggingLevel: LoggingLevel = TiledGlobals.default.loggingLevel, _ completion: ((_ tilemap: SKTilemap) -> Void)? = nil)
Parameters
url
Tiled file url.
withTilesets
pre-loaded tilesets.
ignoreProperties
don’t parse custom properties.
loggingLevel
logging verbosity.
completion
optional completion handler.
-
Load and setup a named TMX file, with optional tilesets. Allows for an optional completion handler.
Declaration
Swift
@available(*, deprecated, renamed: "setup(tmxFile:delegate:inDirectory:withTilesets:ignoreProperties:loggingLevel:_:﹚") open func setup(tmxFile: String, inDirectory: String? = nil, withTilesets tilesets: [SKTileset] = [], ignoreProperties: Bool = false, loggingLevel: LoggingLevel = TiledGlobals.default.loggingLevel, _ completion: ((_ tilemap: SKTilemap) -> Void)? = nil)
Parameters
tmxFile
TMX file name.
inDirectory
search path for assets.
tilesets
optional pre-loaded tilesets.
ignoreProperties
don’t parse custom properties.
loggingLevel
logging verbosity.
completion
optional completion handler.