Tracking the player's progress
First, we need to keep track of how far the player has flown. We will use this later as well, for keeping track of a high score. This is easy to implement. Follow these steps to track how far the player has flown:
In the
GameScene.swift
file, add two new properties to theGameScene
class:Â Â Â Â Â Â Â let initialPlayerPosition = CGPoint(x: 150, y: 250) Â Â Â Â Â Â var playerProgress = CGFloat()
In the
didMove
function, update the line that positions the player to use the newinitialPlayerPosition
constant instead of the old hardcoded value:Â Â Â Â Â Â Â // Add the player to the scene: Â Â Â Â Â Â player.position = initialPlayerPosition
In the
didSimulatePhysics
function, update the newplayerProgress
property with the player's new distance:       // Keep track of how far the player has flown       playerProgress = player.position.x - initialPlayerPosition.x
Perfect! We now have access to the player's progress at all times in the GameScene
class. We can use the...