SKTiledSceneCamera
public class SKTiledSceneCamera : SKCameraNode
extension SKTiledSceneCamera: TiledCustomReflectableType
The SKTiledSceneCamera is a custom scene camera that responds to finger gestures and mouse events.
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.
-
World container node.
Declaration
Swift
weak public var world: SKNode? -
Camera zoom level.
Declaration
Swift
public var zoom: CGFloat -
Camera rotation (in degrees).
Declaration
Swift
@objc public override var rotation: CGFloat { get set } -
Initial camera zoom.
Declaration
Swift
public var initialZoom: CGFloat -
Movement constraints.
Declaration
Swift
public var allowMovement: Bool -
Camera can adjust zoom.
Declaration
Swift
public var allowZoom: Bool -
Camera can rotate.
Declaration
Swift
public var allowRotation: Bool -
Restore normal rotation values after a certain period.
Declaration
Swift
public var restoreRotation: Bool -
Amount to dampen the camera rotation.
Declaration
Swift
public var rotationDamping: CGFloat -
Allow gesture recognition.
Declaration
Swift
public var allowGestures: Bool { get set } -
Zoom minimum constraint.
Declaration
Swift
public var minZoom: CGFloat -
Zoom maximum constraint.
Declaration
Swift
public var maxZoom: CGFloat -
Ignore mix/max zoom constraints.
Declaration
Swift
public var ignoreZoomConstraints: Bool -
Allow the camera zoom to be inverted.
Declaration
Swift
public var allowNegativeZoom: Bool -
Returns true if the camera is zoomed out completely.
Declaration
Swift
public var isAtMaxZoom: Bool { get } -
Indicates the camera is currently moving.
Declaration
Swift
public private(set) var isMoving: Bool { get } -
Update delegates on visible node changes.
Declaration
Swift
public var notifyDelegatesOnContainedNodesChange: Bool { get set } -
Returns all SKTiled nodes contained within the camera view.
Declaration
Swift
public var containedNodes: [SKNode] { get } -
Camera control mode (tvOS).
Declaration
Swift
public var controlMode: CameraControlMode { get set } -
Clamping factor used to alleviate render artifacts like cracking.
Declaration
Swift
public var zoomClamping: CameraZoomClamping { get set } -
Flag to ignore zoom clamping.
Declaration
Swift
public var ignoreZoomClamping: Bool -
Logging verbosity.
Declaration
Swift
public var loggingLevel: LoggingLevel -
Gesture recognizer to handle camera pan actions.
-
Gesture recognizer to handle double-tap events.
-
Gesture recognizer to handle pinch actions.
-
Gesture recognizer to handle touch rotation actions.
-
Flag to show the overlay.
Declaration
Swift
public var showOverlay: Bool { get set }
-
Initialize the camera with a
SKViewand world node references.Declaration
Swift
public init(view: SKView, world node: SKNode)Parameters
viewparent view.
nodeworld container node.
-
Instantiate the map with a decoder instance.
Declaration
Swift
required public init?(coder aDecoder: NSCoder)Parameters
aDecoderdecoder.
-
Setup gesture recognizers for navigating the scene.
-
Enable/disable camera callbacks for all delegates.
Declaration
Swift
public func enableDelegateCallbacks(_ value: Bool)Parameters
valueenable delegate callbacks.
-
Add a camera delegate to allow it to be notified of camera changes.
Declaration
Swift
public func addDelegate(_ delegate: TiledSceneCameraDelegate)Parameters
delegatecamera delegate.
-
Disconnect a camera delegate.
Declaration
Swift
public func removeDelegate(_ delegate: TiledSceneCameraDelegate)Parameters
delegatecamera delegate.
-
Add a node to the overlay node.
Declaration
Swift
public func addToOverlay(_ node: SKNode, zpos: CGFloat = 0)Parameters
nodenode.
-
Apply zooming to the world node (as scale).
Declaration
Swift
public func setCameraZoom(_ scale: CGFloat, interval: TimeInterval = 0, update: Bool = true)Parameters
scalezoom amount.
intervalzoom transition time.
updateupdate the contained nodes.
-
Apply zooming to the camera at a specific location.
Declaration
Swift
public func setCameraZoomAtLocation(scale: CGFloat, location: CGPoint)Parameters
scalezoom amount.
locationzoom location.
-
Set the camera min/max zoom values. This setting will be ignored if the
SKTiledSceneCamera.ignoreZoomConstraintsproperty isfalse.Declaration
Swift
public func setZoomConstraints(minimum: CGFloat, maximum: CGFloat)Parameters
minimumminimum zoom vector.
maximummaximum zoom vector.
-
Update the camera bounds. Camera delegates are notified automatically with the changes.
Declaration
Swift
public func setCameraBounds(bounds: CGRect)Parameters
boundscamera view bounds.
-
Move the camera to a given location in the scene.
Declaration
Swift
public func moveCamera(location: CGPoint, previous: CGPoint)Parameters
locationnew location.
previousold 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
pointpoint to move to.
durationduration of move.
-
Center the camera on a location in the scene.
Declaration
Swift
public func centerOn(scenePoint point: CGPoint, duration: TimeInterval = 0)Parameters
pointpoint in scene.
durationease in/out speed.
-
Center the camera on a node in the scene.
Declaration
Swift
public func centerOn(_ node: SKNode, duration: TimeInterval = 0)Parameters
nodenode in scene.
durationease in/out speed.
-
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
scalecamera 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
newSizeupdated scene size.
transitiontransition time.
-
Returns the points of the camera’s bounding shape.
Declaration
Swift
@objc public func getVertices() -> [CGPoint]Return Value
array of points.
-
Custom camera info description.
Declaration
Swift
public override var description: String { get }
-
Dump camera statistics to the console.
Declaration
Swift
public func dumpStatistics() -
Returns a “nicer” node name, for usage in the inspector.
Declaration
Swift
@objc public var tiledNodeNiceName: String { get } -
Returns the internal Tiled node type icon.
Declaration
Swift
@objc public var tiledIconName: String { get } -
A description of the node used in list or outline views.
Declaration
Swift
@objc public var tiledListDescription: String { get } -
A description of the node used for list views.
Declaration
Swift
@objc public var tiledHelpDescription: String { get }
-
Update the scene camera when a pan gesture is recogized.
-
Handler for double-tap gestures.
-
Handler for pinch gesture events. Updates the camera scale in the scene.
-
Handler for multi-touch rotation events. Updates the camera rotation in the scene.
-
Handler for mouse down events.
Declaration
Swift
public override func mouseDown(with event: NSEvent)Parameters
eventmouse event.
-
Handler for mouse up events.
Declaration
Swift
public override func mouseUp(with event: NSEvent)Parameters
eventmouse 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
eventmouse event.
-
Tracks mouse drag events.
Declaration
Swift
public override func mouseDragged(with event: NSEvent)Parameters
eventmouse 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
eventmouse 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.receiveCameraUpdatesproperty set totruein order for these events to be forwarded.Declaration
Swift
public override func rightMouseDown(with event: NSEvent)Parameters
eventmouse 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.receiveCameraUpdatesproperty set totruein order for these events to be forwarded.Declaration
Swift
public override func rightMouseUp(with event: NSEvent)Parameters
eventmouse right-click event.
-
Handler for mouse drag events.
Declaration
Swift
public func scenePositionChanged(with event: NSEvent)Parameters
eventmouse drag event.
-
Handler for mouse drag events (with option modifier).
Declaration
Swift
public func sceneRotationChanged(with event: NSEvent)Parameters
eventmouse drag event.
-
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
newSizeupdated scene size.
transitiontransition time.
verboselogging verbosity.
View on GitHub
Install in Dash
SKTiledSceneCamera Class Reference