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

Retrofitting the Player class for flight


We need to perform a few quick setup tasks before we can react to player input. We will remove some of our older testing code and add a physics body to the Player class.

The Beekeeper

First, clean up the old bee physics tests from the last chapter. Open GameScene.swift, find didMoveToView, and locate the bottom two lines; one sets a mass for bee2, the other applies an impulse to bee2. Remove these lines.

Updating the Player class

We need to give the Player class its own update function. We want to store player-related logic in Player, and we need it to run before every frame.

  1. Open Player.swift and add the following function inside Player:

    func update() { }
  2. In GameScene.swift, add this code at the bottom of the GameScene class:

    override func update(currentTime: NSTimeInterval) {
        player.update()
    }

Perfect. The GameScene class will call the player class update function on every update.

Moving the ground

We initially placed the ground higher than necessary to...