-1

I'm have a game, and I'm trying to load a scene other than GameScene. That scene is called MenuScene. I have both a .sks file and .swift file for MenuScene, both called MenuScene. Running the following code in GameViewController, I can at least load MenuScene.sks

    if let view = self.view as! SKView? {

        if let scene = SKScene(fileNamed: "MenuScene") {
            scene.scaleMode = .aspectFill
            view.presentScene(scene)
        }

        view.ignoresSiblingOrder = true
        view.showsFPS = false
        view.showsNodeCount = false
    }

I don't think that MenuScene.swift is being accessed though. I know that didMove(to view: ) isn't getting called, and I thought that when an .sks file loads, the corresponding swift file gets run too, but that appears to not be the case. I have code in MenuScene.swift that I need to be run, but I can't figure out why it's not being run. Help.

Jean Valjean
  • 747
  • 1
  • 9
  • 30

1 Answers1

0

The problem here is that, in Xcode, you have to explicitly connect MenuScene.sks to MenuScene.swift

To do this, open MenuScene and go over to the right to the menu. Click on the Custom Class Inspector tab. Then you'll have to enter MenuScene into the Custom Class form.

enter image description here

That will connect the two files, so that when you present the scene, Xcode knows what to open.

Jean Valjean
  • 747
  • 1
  • 9
  • 30