SKTiledSceneCamera

public class SKTiledSceneCamera : SKCameraNode

Overview

Custom scene camera that responds to finger gestures and mouse events.

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

Properties

Property Description
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.

Init

  • Initialize the camera with SKView and world node reference.

    Declaration

    Swift

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

    Parameters

    view

    SKView? optional view.

    world

    SKNode world container node.

Gestures

Delegates

Overlay

Zooming

  • Apply zooming to the world node (as scale).

    Declaration

    Swift

    public func setCameraZoom(_ scale: CGFloat, interval: TimeInterval = 0)

    Parameters

    scale

    CGFloat zoom amount.

  • Apply zooming to the camera based on location.

    Declaration

    Swift

    public func setCameraZoomAtLocation(scale: CGFloat, location: CGPoint)

    Parameters

    scale

    CGFloat zoom amount.

    location

    CGPoint zoom location.

  • Set the camera min/max zoom values.

    Declaration

    Swift

    public func setZoomConstraints(minimum: CGFloat, maximum: CGFloat)

    Parameters

    minimum

    CGFloat minimum zoom vector.

    maximum

    CGFloat maximum zoom vector.

Bounds

Movement

  • Move the camera to the given location.

    Declaration

    Swift

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

    Parameters

    location

    CGPoint new location.

    previous

    CGPoint old location.

  • Move camera manually.

    Declaration

    Swift

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

    Parameters

    point

    CGPoint point to move to.

    duration

    TimeInterval duration of move.

  • Center the camera on a location in the scene.

    Declaration

    Swift

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

    Parameters

    scenePoint

    CGPoint point in scene.

    easeInOut

    TimeInterval ease in/out speed.

  • Center the camera on a node in the scene.

    Declaration

    Swift

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

    Parameters

    scenePoint

    SKNode node in scene.

    easeInOut

    TimeInterval ease in/out speed.

  • Reset the camera position & zoom level.

    Declaration

    Swift

    public func resetCamera()
  • Reset the camera position & zoom level.

    Declaration

    Swift

    public func resetCamera(toScale scale: CGFloat)

    Parameters

    toScale

    CGFloat 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, verbose: Bool = false)

    Parameters

    newSize

    CGSize updated scene size.

    transition

    TimeInterval transition time.

Geometry

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

    Declaration

    Swift

    public func getVertices() -> [CGPoint]

    Return Value

    [CGPoint] array of points.

  • Current clamp status

    Declaration

    Swift

    public var clampDescription: String { get }
  • ▶︎description

    Custom camera info description.

    Declaration

    Swift

    override public var description: String { get }

Gesture Handlers

Mouse Handlers

  • Handler for mouse click events.

    Declaration

    Swift

    override public func mouseDown(with event: NSEvent)

    Parameters

    event

    NSEvent 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

    override public func mouseMoved(with event: NSEvent)

    Parameters

    event

    NSEvent mouse event.

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

    Declaration

    Swift

    override public func scrollWheel(with event: NSEvent)
  • Callback for mouse drag events.

    Declaration

    Swift

    public func scenePositionChanged(with event: NSEvent)

    Parameters

    event

    NSEvent mouse drag event.