Book Image

Game Development with Swift

By : Stephen Haney
Book Image

Game Development with Swift

By: Stephen Haney

Overview of this book

Table of Contents (18 chapters)
Game Development with Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Improving the camera


Our camera code works well; it follows the player wherever they fly. However, we can improve the camera to enhance the flying experience. In this section, we will add two new features:

  • Zoom the camera out as Pierre Penguin flies higher, reinforcing the feeling of increasing height.

  • Suspend vertical centering when the player drops below the halfway point of the screen. This means the ground never fills too much of the screen, and adds the feeling of cutting upwards into the air when Pierre flies higher and the camera starts tracking him again.

Follow these steps to implement these two improvements:

  1. In GameScene.swift, create a new variable in the GameScene class to store the center point of the screen:

    var screenCenterY = CGFloat()
  2. In the didMoveToView function, set this new variable with the calculated center of the screen's height:

    // Store the vertical center of the screen:
    screenCenterY = self.size.height / 2
  3. We need to rework the didSimulatePhysics function significantly...