Adding a SpriteKit overlay

To show the score and a button, we will add it to the 2D SpriteKit layer. To add the overlay, create a class called OverlaySKscene. In the class, add the following:

import SpriteKit

class OverlaySKScene: SKScene {
    
    let _gameScene: GameSCNScene!
    let myLabel: SKLabelNode!
    var gameOverLabel: SKLabelNode!
    var jumpBtn: SKSpriteNode!
    var playBtn: SKSpriteNode!
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    init(size: CGSize, gameScene: GameSCNScene){

super.init(size: size)
    
    }
}

We import SpriteKit as we will have to create a SubClass of SpriteKit. Create global variables of type GameSCNScene, SKLabelNodes, and SpriteNodes. Here, we create two LabelNodes: one for displaying the ...

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.