Oliver Redeyoff
Oliver Redeyoff

Reputation: 197

Creating a menu in swift sprite kit

I am trying to have a swift file called MenuScene.swift that is run before the GameScene.swift but I don't know how. I have tried modifying this line in GameViewController :

if let scene = GameScene(fileNamed:"GameScene") {

to :

if let scene = MenuScene(fileNamed:"MenuScene") {

But it just shows a blank scene. Is there anything else that I have to do in order to make it work?

Upvotes: 2

Views: 238

Answers (1)

Ron Myschuk
Ron Myschuk

Reputation: 6071

I know you figured this out by adding the MenuScene.sks file, but if you already have the code file and just want to load it and not add the sks file you can just change the viewDidLoad in GameViewController to the following...

override func viewDidLoad() {

    super.viewDidLoad()

    if let skView = self.view as? SKView {

        if skView.scene == nil {

            let scene = MenuScene(size: skView.bounds.size)

            skView.showsFPS = false
            skView.showsNodeCount = false
            skView.showsPhysics = false
            skView.ignoresSiblingOrder = true

            scene.scaleMode = .AspectFill

            skView.presentScene(scene)
        }
    }
}

Upvotes: 1

Related Questions