Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Game Development with Swift
  • Table Of Contents Toc
Game Development with Swift

Game Development with Swift

By : Stephen Haney
4.6 (14)
close
close
Game Development with Swift

Game Development with Swift

4.6 (14)
By: Stephen Haney

Overview of this book

If you wish to create and publish fun iOS games using Swift, then this book is for you. You should be familiar with basic programming concepts. However, no prior game development or Apple ecosystem experience is required.
Table of Contents (13 chapters)
close
close
12
Index

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:

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 createHudNodes function:

    // Add the restart and menu button textures to the nodes:
    restartButton.texture = 
        textureAtlas.textureNamed("button-restart.png")
    menuButton.texture = 
        textureAtlas.textureNamed("button-menu.png")
    // Assign node names to the buttons:
    restartButton.name = "restartGame"
    menuButton.name = "returnToMenu"
    // Position the...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Game Development with Swift
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon