Adding text and crosshair

Let's see how to add basic game objects, such as a regular sprite and text, to the scene.

At the top of the Scene.swift class, add crosshair of type SKSpriteNode and scoreText of type SKLabelNode called crosshair and scoreText as follows:

import SpriteKit
import ARKit

class Scene: SKScene {
    
   
    var crosshair: SKSpriteNode!
    let scoreText = SKLabelNode(text: "00")

Also create a new ARSKView called sceneView, which will return the current view as ARSKView. This is because we need to access the current view often:

    var sceneView: ARSKView {
        return view as! ARSKView
    }

The crosshair image is provided in the assets for the chapter. Copy and include it in the current project's assets, as follows:

In the viewDidLoad function, add the following ...

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.