O'Reilly logo

Swift 3 Game Development - Second Edition by Stephen Haney

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Centering the camera on a sprite

Games often require that the camera follows the player sprite as it moves through space. We definitely want this camera behavior for Pierre, our penguin character, whom we will soon be adding to the game. With iOS9, Apple added a new SKCameraNode class that makes this task easy. We will attach a SKCameraNode to our scene and position it directly over the player to keep their character centered in the view.

You can find the code for our camera functionality in the following code block. Read the comments for a detailed explanation. This is a quick recap of the changes:

  • Our didMove function was becoming too crowded. I broke out our flying bee code into a new function named addTheFlyingBee. Later, we will encapsulate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required