A node that controls camera movement, zoom and rotation.


class SKCameraNode : SKNode


An SKCameraNode object is used to specify a position in the scene that the scene can be rendered from. If a camera node is placed in the scene and the scene’s camera property is set to the camera node, then the scene is rendered using the camera node’s properties. Because the camera is a node, it can be moved just like any other node in the scene using actions, physics, and so on. When a scene is rendered using a camera node, the following things occur:

  • The scene is rendered so that the camera node’s origin is placed in the middle of the scene.

  • The inverse of the camera node’s xScale, yScale, and zRotation properties are applied to all nodes in the scene.

In this way, a camera’s position, scale, and rotation always have the opposite effect on how the scene is rendered. For example, if the camera is moved 10 pixels to the right, then the scene is rendered as if everything else moved 10 pixels to the left. And similarly, if a camera node has an xScale and yScale of 2.0, then scene is rendered as if every distance was half its normal size, effectively increasing the visible area of the camera’s viewport.

The camera’s viewport is the same size as the scene’s viewport (determined by the scene’s size property) and the scene is still scaled by its scaleMode property when it is rendered into the view.


Testing Nodes for Visibility

func containedNodeSet() -> Set<SKNode>

Finds nodes that are visible in the camera's viewport.

func contains(SKNode) -> Bool

Checks to see if a node is visible in the camera’s viewport.

See Also

Cameras and Lighting

class SKLightNode

A node that adds lighting into a scene.