1
votes

I'm new to Swift and have no Objective-c experience. I already have a working Swift game that I programed using SpriteKit and a not functional Menu also in SpriteKit. Im trying to figure out how to integrate this two but I can't find information on how to handle SKScene (I asume). Currently if I Run the file it goes straight to the game and I want to first launch the menu and when a button is pressed to jump to the game. How or where can I learn to do this?

My two file clases are as follows:

class GameScene: SKScene, SKPhysicsContactDelegate {
// handles the game
} 

class Menu: SKScene {
//handles the menu
}

thank you

1

1 Answers

1
votes

You should have ViewController.swift after you make standart SpriteKit application. Your game scene is created and displayed in this file. To first show the menu, it is necessary to replace the game scene creating to menu scene creating. And your game scene must be created on menu scene object. It may look something like this:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let scene = Menu(size: CGSize(width: 1024, height: 768))
        let skView = self.view as SKView
        skView.ignoresSiblingOrder = true
        scene.scaleMode = .AspectFill
        skView.presentScene(scene)
    }
    ....
}

class Menu: SKScene {
    ...
    func startPlayButtonPressEvent() {
        let skView = self.view as SKView
        skView.ignoresSiblingOrder = true
        let scene = GameScene(size: skView.bounds.size)
        scene.scaleMode = .AspectFill
        skView.presentScene(scene)
    }
    ...
}