Adding a few touches

Although a few things are still missing, either some parts of them are straightforward or we already implemented them in the previous chapters when we were building Flappy Swift.

The score

The score falls under the straightforward category, and it is worth implement it right now so that we can finish adding all the visual elements to the screen.

The goal of the game is for the player to keep going as long as they can without colliding with a cube. So, to implement the score, we just need to schedule a timer that fires every second, increasing the score. First of all, we need to add elements as properties:

class GameViewController: UIViewController { //... private var laneTimer: NSTimer! private let scoreLbl = UILabel() private ...

Get Swift 2 By Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.