Add a Camera to Track the Player

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 ...

Get Apple Game Frameworks and Technologies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.