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 = let (scoreLableMinVec, scoreLableMaxVec) = scoreLabel.boundingBox let scoreBound = SCNVector3(x: ...

Get Swift Game Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.