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.

SKTiledScene Hierarchy

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.

Initialization

  • 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.

Setup

Tilemap Delegate

Tileset Delegate

Updating

  • 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 the SKTIledScene.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 the SKTIledScene.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).

Delegate Methods

Deprecations

  • 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.