O'Reilly logo

Swift Game Development - Third Edition by Stephen Haney, Siddharth Shekar

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 Score and Gameover text

Just as we can have 3D game objects, we can also have 3D text. We will create 3D text and make it part of the world instead of adding it to the screen space, which is what we have done so far.

Add the following lines to add the SCNText and SCNNode to the current class:

    var scoreLabel: SCNText!
    var scoreNode: SCNNode!
    
    var gameOverLabel: SCNText!
    var gameOverNode: SCNNode!

In the setupGame function, add the following lines of code to add the 3D text to the scene:

 scoreLabel = SCNText(string: "Score: 0", extrusionDepth: 0.2) scoreLabel.font = UIFont(name: "Arial", size: 4) scoreLabel.firstMaterial!.diffuse.contents = UIColor.blue let (scoreLableMinVec, scoreLableMaxVec) = scoreLabel.boundingBox let scoreBound = SCNVector3(x: ...

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