Reputation: 35
I have created a platformer game, and I when I start the game, it goes straight into playing. I would like to have a menu that has a button to start the game and a button which would lead to a shop, to purchase different backgrounds or characters with in game currency that has been earned. I would appreciate it if someone could help me to implement this kind of menu. It would also be great if I could get help on how to pause the game while playing.
Upvotes: 3
Views: 3027
Reputation: 4046
You could create scene for menu. When user push start button you present your game scene.
class MenuScene: SKScene {
override func didMoveToView(view: SKView) {
addButtons()
}
private func addButtons() {
// TODO layout buttons here
}
private func startGame() {
let gameScene = GameScene(size: view!.bounds.size)
let transition = SKTransition.fadeWithDuration(0.15)
view!.presentScene(gameScene, transition: transition)
}
}
And present it from your controller:
override func viewDidLoad() {
super.viewDidLoad()
let sceneView = view as! SKView
// sceneView.showsFPS = true
// sceneView.showsNodeCount = true
sceneView.ignoresSiblingOrder = true
scene = MenuScene(size: view.bounds.size)
scene.scaleMode = .ResizeFill
sceneView.presentScene(scene)
}
Upvotes: 7