O'Reilly logo

Game Development with Swift by Stephen Haney

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding the restart game menu

The restart menu is even simpler to implement. Rather than create a new scene, we can extend our existing HUD class to display a restart button when the game ends. We will also include a smaller button to return the player to the main menu. This menu will appear on top of the action, as in this screenshot:

Adding the restart game menu

Extending the HUD

First, we need to create and draw our new button nodes in the HUD class. Follow these steps to add the nodes:

  1. Open the HUD.swift file and add two new properties to the HUD class, as follows:
    let restartButton = SKSpriteNode()
    let menuButton = SKSpriteNode()
  2. Add the following code at the bottom of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required