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 lines of code to add the crosshair and text to the scene:
override func didMove(to view: SKView) { // Setup your scene here crosshair = SKSpriteNode(imageNamed...