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. |
-
▶︎zoomCamera zoom level.
Declaration
Swift
public var zoom: CGFloat -
Initial zoom level.
Declaration
Swift
public var initialZoom: CGFloat -
Camera can move freely.
Declaration
Swift
public var allowMovement: Bool -
Camera can change zoom amount.
Declaration
Swift
public var allowZoom: Bool -
Camera can rotate.
Declaration
Swift
public var allowRotation: Bool -
▶︎minZoomMinimum zoom constraint.
Declaration
Swift
public var minZoom: CGFloat -
▶︎maxZoomMaximum zoom constraint.
Declaration
Swift
public var maxZoom: CGFloat -
Ignore mix/max zoom constraints
Declaration
Swift
public var ignoreZoomConstraints: Bool -
Returns true if the camera zoom level is at the maximum allowed value.
Declaration
Swift
public var isAtMaxZoom: Bool { get } -
Update delegates on visible node changes.
Declaration
Swift
public var notifyDelegatesOnContainedNodesChange: Bool -
Contained nodes
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 -
Gesture recognizer to recognize camera panning
-
Gesture recognizer to recognize double taps
-
Gesture recognizer to recognize pinch actions
-
Turn off to not respond to gestures
Declaration
Swift
public var allowGestures: Bool { get set } -
Flag to show the overlay
Declaration
Swift
public var showOverlay: Bool { get set }
-
Initialize the camera with SKView and world node reference.
Declaration
Swift
public init(view: SKView, world node: SKNode)Parameters
viewSKView?optional view.worldSKNodeworld container node.
-
Setup gesture recognizers for navigating the scene.
-
Enable/disable camera callbacks for all delegates.
Declaration
Swift
public func enableDelegateCallbacks(_ value: Bool)Parameters
valueBoolenable delegate callbacks. -
Add a camera delegate to allow it to be notified of camera changes.
Declaration
Swift
public func addDelegate(_ delegate: SKTiledSceneCameraDelegate)Parameters
delegateSKTiledSceneCameraDelegatecamera delegate. -
Disconnect a camera delegate.
Declaration
Swift
public func removeDelegate(_ delegate: SKTiledSceneCameraDelegate)Parameters
delegateSKTiledSceneCameraDelegatecamera delegate.
-
Add an overlay node.
Declaration
Swift
public func addToOverlay(_ node: SKNode)
-
Apply zooming to the world node (as scale).
Declaration
Swift
public func setCameraZoom(_ scale: CGFloat, interval: TimeInterval = 0)Parameters
scaleCGFloatzoom amount. -
Apply zooming to the camera based on location.
Declaration
Swift
public func setCameraZoomAtLocation(scale: CGFloat, location: CGPoint)Parameters
scaleCGFloatzoom amount.locationCGPointzoom location. -
Set the camera min/max zoom values.
Declaration
Swift
public func setZoomConstraints(minimum: CGFloat, maximum: CGFloat)Parameters
minimumCGFloatminimum zoom vector.maximumCGFloatmaximum zoom vector.
-
Update the camera bounds.
Declaration
Swift
public func setCameraBounds(bounds: CGRect)Parameters
boundsCGRectcamera view bounds.
-
Move the camera to the given location.
Declaration
Swift
public func moveCamera(location: CGPoint, previous: CGPoint)Parameters
locationCGPointnew location.previousCGPointold location. -
Move camera manually.
Declaration
Swift
public func panToPoint(_ point: CGPoint, duration: TimeInterval = 0.3)Parameters
pointCGPointpoint to move to.durationTimeIntervalduration of move. -
Center the camera on a location in the scene.
Declaration
Swift
public func centerOn(scenePoint point: CGPoint, duration: TimeInterval = 0)Parameters
scenePointCGPointpoint in scene.easeInOutTimeIntervalease in/out speed. -
Center the camera on a node in the scene.
Declaration
Swift
public func centerOn(_ node: SKNode, duration: TimeInterval = 0)Parameters
scenePointSKNodenode in scene.easeInOutTimeIntervalease 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
toScaleCGFloatcamera 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
newSizeCGSizeupdated scene size.transitionTimeIntervaltransition time.
-
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 } -
Custom camera info description.
Declaration
Swift
override public var description: String { get }
-
Update the scene camera when a pan gesture is recogized.
-
Handler for double taps.
-
Update the camera scale in the scene.
-
Handler for mouse click events.
Declaration
Swift
override public func mouseDown(with event: NSEvent)Parameters
eventNSEventmouse 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
eventNSEventmouse 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
eventNSEventmouse drag event.
View on GitHub
SKTiledSceneCamera Class Reference