SKTiledSceneCamera

public class SKTiledSceneCamera : SKCameraNode
extension SKTiledSceneCamera: TiledCustomReflectableType

The SKTiledSceneCamera is a custom scene camera that responds to finger gestures and mouse events.

Camera Hierarchy

This node is a custom camera meant to be used with a scene conforming to the TiledSceneDelegate protocol. The camera defines a position in the scene to render the scene from, with a reference to the TiledSceneDelegate.worldNode to interact with tile maps.

Properties

  • world: world container node.
  • delegates: array of delegates to notify about camera updates.
  • zoom: camera zoom value.
  • allowMovement: toggle to allow camera movement.
  • minZoom: minimum zoom value.
  • maxZoom: maximum zoom value.
  • zoomClamping: clamping factor used to alleviate render artifacts like cracking.

For more information, see the Tiled Scene Camera page in the official documentation.

Overlay

Initialization

  • Initialize the camera with a SKView and world node references.

    Declaration

    Swift

    public init(view: SKView, world node: SKNode)

    Parameters

    view

    parent view.

    node

    world container node.

  • Instantiate the map with a decoder instance.

    Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)

    Parameters

    aDecoder

    decoder.

Gestures

Delegates

Overlay

Zooming

Bounds

  • Update the camera bounds. Camera delegates are notified automatically with the changes.

    Declaration

    Swift

    public func setCameraBounds(bounds: CGRect)

    Parameters

    bounds

    camera view bounds.

Movement

  • Move the camera to a given location in the scene.

    Declaration

    Swift

    public func moveCamera(location: CGPoint, previous: CGPoint)

    Parameters

    location

    new location.

    previous

    old location.

  • Pan the camera manually. Optionally, a duration can be specified for the movement.

    Declaration

    Swift

    public func panToPoint(_ point: CGPoint, duration: TimeInterval = 0.3)

    Parameters

    point

    point to move to.

    duration

    duration of move.

  • Center the camera on a location in the scene.

    Declaration

    Swift

    public func centerOn(scenePoint point: CGPoint, duration: TimeInterval = 0)

    Parameters

    point

    point in scene.

    duration

    ease in/out speed.

  • Center the camera on a node in the scene.

    Declaration

    Swift

    public func centerOn(_ node: SKNode, duration: TimeInterval = 0)

    Parameters

    node

    node in scene.

    duration

    ease in/out speed.

Camera Reset

  • Reset the camera position & zoom level.

    Declaration

    Swift

    public func resetCamera(duration: TimeInterval = 0)
  • Reset the camera position & zoom level.

    Declaration

    Swift

    public func resetCamera(toScale scale: CGFloat, duration: TimeInterval = 0)

    Parameters

    scale

    camera scale.

  • Center & fit the current tilemap in the frame when the parent scene is resized.

    Declaration

    Swift

    public func fitToView(newSize: CGSize, transition: TimeInterval = 0)

    Parameters

    newSize

    updated scene size.

    transition

    transition time.

Geometry

  • Returns the points of the camera’s bounding shape.

    Declaration

    Swift

    @objc
    public func getVertices() -> [CGPoint]

    Return Value

    array of points.

Extensions

  • Custom camera info description.

    Declaration

    Swift

    public override var description: String { get }

Debugging

Gesture Handlers

Mouse Handlers

  • Handler for mouse down events.

    Declaration

    Swift

    public override func mouseDown(with event: NSEvent)

    Parameters

    event

    mouse event.

  • Handler for mouse up events.

    Declaration

    Swift

    public override func mouseUp(with event: NSEvent)

    Parameters

    event

    mouse event.

  • Track mouse movement in the scene. Location is in local space, so coordinate origin will be the center of the current window.

    Declaration

    Swift

    public override func mouseMoved(with event: NSEvent)

    Parameters

    event

    mouse event.

  • Tracks mouse drag events.

    Declaration

    Swift

    public override func mouseDragged(with event: NSEvent)

    Parameters

    event

    mouse event

  • Manage mouse wheel zooming. Need to ensure that lastLocation is a location in this node.

    Declaration

    Swift

    public override func scrollWheel(with event: NSEvent)

    Parameters

    event

    mouse wheel event.

  • Handler for mouse right-click events. The mouse event is forwarded to any delegates implementing the TiledSceneCameraDelegate.rightMouseDown(event:) method.

    Important

    delegates need to have the TiledSceneCameraDelegate.receiveCameraUpdates property set to true in order for these events to be forwarded.

    Declaration

    Swift

    public override func rightMouseDown(with event: NSEvent)

    Parameters

    event

    mouse right-click event.

  • Handler for mouse right-click events. The mouse event is forwarded to any delegates implementing the TiledSceneCameraDelegate.sceneRightClicked(event:) method.

    Important

    delegates need to have the TiledSceneCameraDelegate.receiveCameraUpdates property set to true in order for these events to be forwarded.

    Declaration

    Swift

    public override func rightMouseUp(with event: NSEvent)

    Parameters

    event

    mouse right-click event.

Movement Handlers

Deprecations

  • Center & fit the current tilemap in the frame when the parent scene is resized.

    Declaration

    Swift

    @available(*, deprecated, renamed: "SKTiledSceneCamera.fitToView(newSize:transition:﹚")
    public func fitToView(newSize: CGSize, transition: TimeInterval = 0, verbose: Bool = false)

    Parameters

    newSize

    updated scene size.

    transition

    transition time.

    verbose

    logging verbosity.