
Swift 3 Game Development
By :

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.
First, clean up the old bee physics tests from the last chapter. Open GameScene.swift
, find didMove
and locate the bottom two lines; one sets a mass for bee2
, and the other applies an impulse to bee2
. Remove these two lines:
bee2.physicsBody?.mass = 0.2 bee2.physicsBody?.applyImpulse(CGVector(dx: -25, dy: 0))
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:
Open Player.swift
and add the following function inside Player
:
func update() { }
In GameScene.swift
, add this code at the bottom of the GameScene
class:
override func update(_ currentTime: TimeInterval) { player.update() }
Perfect. The GameScene
class will...