Book Image

Game Development with Swift

By : Stephen Haney
Book Image

Game Development with Swift

By: Stephen Haney

Overview of this book

Table of Contents (18 chapters)
Game Development with Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Building the main menu


We can use SpriteKit components to build our main menu. We will create a new scene in a new file for our main menu, and then use code to place a background sprite node, logo text node, and button sprite nodes. Let's start by adding the menu scene to the project and building out the nodes.

Creating the menu scene and menu nodes

To create the menu scene, follow these steps:

  1. We will use a new background image for the menu. Let's add it to our project.

    1. Locate Background-menu.png in the Backgrounds folder of the asset bundle.

    2. Open Images.xcassets in Xcode, and then drag and drop Background-menu.png into Images.xcassets to make it available in your project.

  2. Add a new Swift file to your project named MenuScene.swift.

  3. Add the following code to create the MenuScene scene class:

    import SpriteKit
    
    class MenuScene: SKScene {
        // Grab the HUD texture atlas:
        let textureAtlas:SKTextureAtlas = 
            SKTextureAtlas(named:"hud.atlas")
        // Instantiate a sprite node for the start...