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: scoreLableMaxVec.x - scoreLableMinVec.x, y: scoreLableMaxVec.y - scoreLableMinVec.y, z:...