camera
The camera node in the scene that determines what part of the scene’s coordinate space is visible in the view.
Declaration
weak var camera: SKCameraNode? { get set }Mentioned in
Discussion
The default value of this property is nil, which means that the scene’s anchorPoint and size properties determine what portion of the scene is visible. If set to point to a camera node contained in the scene, the anchorPoint property is ignored and the scene is rendered using the camera node’s properties instead.
A camera must be added as a child of the scene for it to render that scene.
Listing 1 shows, in Swift, how to add a camera to an SKScene named scene. The camera is positioned in the center of the scene which gives the same result as rendering a camera-less scene with an anchorPoint of zero.
Listing 1. Adding a camera to a scene
let cameraNode = SKCameraNode()
cameraNode.position = CGPoint(x: scene.size.width / 2,
y: scene.size.height / 2)
scene.addChild(cameraNode)
scene.camera = cameraNodeFor more information, see SKCameraNode.