简体   繁体   English

在Swift Sprite-Kit游戏中实现游戏菜单

[英]Implementing a game menu in a Swift Sprite-Kit game

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. 如果我可以在玩游戏时如何暂停游戏,那也很棒。

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)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM