Games often require the camera to follow 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, which makes this task easy. We will attach an 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. We broke out our flying bee code into a new function namedaddTheFlyingBee
. Later, we will encapsulate game objects, such as bees, into their own classes.We created two new constants on the
GameScene
class: the camera node and the bee node.We updated the
didMove
function. It assigns the new camera node to the scene's camera.We have added a new function...