SpriteKit game with multiple menu "views", how do I add menu view controllers?

If I have multiple menu screens for my spritekit game, do I just create a normal game from storyboards and the one view controller with the game I use spritekit? Whats the best way to go about adding multiple menu screens?

Depends on how you want it to behave. You can swap out the current scene for a menu scene, or present another view controller showing the menu scene. If one menu scrolls to the second menu, UINavigationController-style, you should probably just add the nodes of the second menu to the right of the nodes of the first menu, all in the same scene.

I declare the menu screen as a separat view in xcode, let call it "ViewMenu", with a separat class "ViewMenu: UIView".

I also declare a protocol like:


protocol ViewMenuDelegate {

func hideMenu()

}


When I Hit the "Exit-Button" in the Menu, I call this delegate-method to send Information to the caller View

Also I declare an interface-method "prepareScreenContent" for example to manipulate the content of the ViewMenu with the current data.


To Call the Menu I use the following steps:


1. Declare a propertie named "theViewMenu" of type "ViewMenu"

2. then Implement the Delegate-Method

func hideInfoView() {

/

UIView.animateWithDuration(0.5, animations: { () -> Void in

/

self.theInfoView.transform = CGAffineTransformMakeScale(0.01, 0.01)

/

}) { _ -> Void in

/

self.theViewMenu.removeFromSuperview()

self.theViewMenu = nil

}

/

}

3. Call the ViewMenu with the following steps

let skView = self.view!

theViewMenu= UIView.loadFromNibNamed("ViewMenu") as! ViewMenu

//- Position on Screen (Center)

let rect = CGRectMake((kScreenWidth/2 -theViewMenu.frame.width) / 2,

(kScreenHeight / 2 - theViewMenuframe.height) / 2,

theViewMenu.frame.width, theViewMenu.frame.height)

theViewMenu.frame = rect

//

theViewMenu.delegate = self

theViewMenu.prepareScreenContent()

theViewMenu.transform = CGAffineTransformMakeScale(0.0, 0.0)

skView.addSubview(theViewMenu)

/

UIView.animateWithDuration(0.5, animations: { () -> Void in

self.theViewMenu.transform = CGAffineTransformMakeScale(1.0, 1.0)

})


Hope this can give you a hint.

I don't think it's a great idea to use multiple views with Sprite Kit. For a start, you end up having to re-invent functionality that Sprite Kit already has for scene transitions (for example, your code above).


Also, because Sprite Kit uses OpenGL (or perhaps Metal, at some point in the future), switching views ends up being a transition between two entirely unrelated GPU environments, because you're likely dumping all the GPU resources from one view to make way for the other view. Merely switching scenes is likely to be more efficient in GPU resource and battery usage.


With Sprite Kit, it seems to me, you should aim to stick with a single SKView (and no subviews) whenever possible, and transition between SKScenes for the different parts of your game.

SpriteKit game with multiple menu "views", how do I add menu view controllers?
 
 
Q