O'Reilly logo

Swift 2 By Example by Giordano Scalzo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required