Getting Started with a Camera

Learn the semantics of using a camera in your scene.

Overview

SKCameraNode defines which portion of a scene is visible on the screen. You must do the following to use a camera:

  1. Instantiate a new SKCameraNode and set it as the scene’s camera.

  2. Add the camera node as a child to the scene.

Because the camera is a node, you define its position within the scene just like any other node. Actions, physics, and GameplayKit behaviors can also be applied to the camera node. When a scene is rendered using a camera node, the following 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, 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, the scene is rendered as if every distance was half its normal size, effectively increasing the visible area of the camera’s viewport.