September 2018
Intermediate to advanced
434 pages
8h 47m
English
So far, the GameScene class is oblivious to whether the player is alive or dead. We need to change that in order to use our new gameOver function. Open Player.swift, locate the die function, and add the following code at the bottom of the function:
// Alert the GameScene:
if let gameScene = self.parent as? GameScene {
gameScene.gameOver()
} We access GameScene by traveling up the node tree. The Player node's parent is the GameScene class.
Run the project and die. You should see the two new buttons appear after death, as shown here:

Good work. The buttons are displaying properly, but nothing happens ...
Read now
Unlock full access