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 score and the other to show the gameover
text. We also create two SpriteNodes
: one for the play button and the other for the jump button.
We add the required init
function and...