MysteryPancake
MysteryPancake

Reputation: 1505

Storyboarding a game's main menu?

So, I'm making a simple game using the iOS game preset, but I'm a bit confused as to the best way of making a main menu. I already have a class for the game scene (it's an SKScene), and most tutorials suggest simply making another similar class for the menu (another SKScene), but when I try to make one I run into a bit of trouble.

The problem is that I don't want to programmatically make the main menu, I'd much rather make it using a storyboard since the drag-and-drop nature of them is much easier to use and shows you instantly what it'll look like in the end, but I can't seem to figure out if it's even possible to do this.

Upvotes: 0

Views: 110

Answers (2)

rayaantaneja
rayaantaneja

Reputation: 1748

I wanted to do the same thing with my SceneKit game and got a Main Menu created from Interface Builder working pretty smoothly. Here's what you'll need:

  1. Buttons
  2. Segues
  3. View Controllers (the destinations for your segues)

Steps:

  1. Open your Storyboard
  2. Press the "+" icon to open the object library
  3. Drag a View Controller onto your Storyboard
  4. Drag as many buttons onto the Storyboard as needed (eg. "Kick off", "Play vs. computer", "Quick Match", etc.)
  5. Arrange the buttons and beautify it as needed

This View Controller will be your main menu. Now, to hook it up to your game scene here is what you do:

  1. Control-drag from the menu button to the View controller that it's supposed to navigate to (in your case it'll be your Game View Controller)
  2. Choose "Present Modally" from the pop-up when you let go of your mouse
  3. Click the newly created segue and go the Attributes Inspector
  4. Change "Presentation" to whatever style you want (I chose "full screen" because I wanted to make it look like the Game Scene is now the "main" view)
  5. Optionally change the "Transition" style (I personally did "page curl" cuz why not)

And that's it! No need to manually create main menus anymore. You can create custom segues by subclassing and you can configure your View Controllers using the various functions that are called during the Segue process (UIStoryboardSegue documentation covers these).

Pro tip: Use @IBInspectable to allow View Controller properties to be configured from within the Attribute Inspector.

class MyCustomViewController: UIViewController {
    @IBInspectable var easy_mode: Bool {
        get { isEasyMode } 
        set { isEasyMode = newValue } 
    }

    var isEasyMode = false

    // ...
}

This way you can configure View Controllers from within the Interface Builder by copy-pasting your Game View Controller in your Storyboard, manually setting the "Easy Mode" attribute to "On", and have a different button in your main menu hooked up to this newly configured View Controller using a segue.

Upvotes: 0

MysteryPancake
MysteryPancake

Reputation: 1505

I ended up just making the menu using code... except now I have to manually implement text resizing. Surprised nobody knew a solution.

Upvotes: 1

Related Questions