Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Swift By Example
  • Table Of Contents Toc
Swift By Example

Swift By Example

By : Giordano Scalzo
4 (2)
close
close
Swift By Example

Swift By Example

4 (2)
By: Giordano Scalzo

Overview of this book

This book is intended for those who want to learn to develop apps in Swift the right way. Whether you are an expert Objective-C programmer or new to this platform, you'll learn quickly, grasping the code of real-world apps to use Swift effectively. Prior experience in development for Apple devices would be helpful, but is not mandatory.
Table of Contents (10 chapters)
close
close

Adding a few touches


Although a few things are still missing, either some parts of them are straightforward or we have 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 worthwhile implementing it right now, so 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 the elements as properties:

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

Then we set up the score, calling setupScore() in createContents():

    func createContents() {
//...
        scene!.fogColor = UIColor.blackColor()
        setupScore()
...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Swift By Example
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon