Add a Camera to Track the Player

Apple Game Frameworks and Technologies — by Tammy Coron (88 / 193)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Chapter 9 Operating the Camera and Using References Nodes | TOC | Use Reference Nodes in Y our Scene 👉

Have you ever watched a movie that has a great storyline, but the director, for whatever reason, makes poor camera decisions? Maybe the camera is too close to an actor or object, or perhaps it’s too low in the scene. The point is: if a scene isn’t shot well, the story could get lost, and the audience might lose interest. Well, the same holds true for game scenes.

Currently, the way the game is set up now, the player can walk right out of the scene, which is not a great “feature” for an exciting new game. To correct this problem, you’ll add a camera node to the scene and use the SKCameraNode class to direct it through code.

The SKCameraNode class is another base node that’s available in SpriteKit. Because the camera node is simply another type of node, you can set the usual properties like position, scale, and rotation. But to use a camera node, you first need to add it to the scene.

To begin, open the valsrevenge project in Xcode.

Using the Starter Project

You may continue using your project from the previous chapter, or you can use the starter project located in the projects/begin folder included with the code resources for this chapter. Either option is fine; the only…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.