1

I am working on a game for macOS using Spritekit. Want to use a second scene. How do I set up App Delegate and ViewController to accomplish that? I can make a transition to a second scene

       var secondScene = SecondScene(size: self.size)
        var transition = SKTransition.flipVertical(withDuration: 1.0)
        secondScene.scaleMode = SKSceneScaleMode.aspectFill
        self.scene!.view?.presentScene(secondScene, transition: transition)

Similar code in the SecondScene to return results in a crash during reloading of the previous scene, which loads fine the first time around.

        self.scene!.view?.presentScene(FirstScene, transition: transition)

This is what my ViewController looks like.

class ViewController: NSViewController {

@IBOutlet var skView: SKView!

@IBOutlet weak var msg: NSTextField!
override func viewDidLoad() {
    super.viewDidLoad()

    if let view = self.skView {
        // Load the SKScene from 'GameScene.sks'
        if let scene = SKScene(fileNamed: "GameScene") {
            // Set the scale mode to scale to fit the window
            scene.scaleMode = .aspectFill

            // Present the scene
            view.presentScene(scene)
        }

        view.ignoresSiblingOrder = true

        view.showsFPS = true
        view.showsNodeCount = true
    }
}

}

Tom
  • 56
  • 5
  • What error do you get? – Whirlwind Mar 15 '17 at 08:07
  • @Whirlwind: What does the ViewController look like in the answer you provided to http://stackoverflow.com/questions/42798574/multiple-scenes-in-macos-spritekit-game?noredirect=1#comment72747735_42798574 ? – Tom Mar 15 '17 at 21:06
  • Put an exception break point and you will know the line that causing crash... – Whirlwind Mar 15 '17 at 21:07
  • By the way, have you considered something like this : http://stackoverflow.com/a/35409586 – Whirlwind Mar 15 '17 at 21:12
  • This is the line of code that throws the exception: 'ledboard = (self.childNode(withName: "//LEDboardTop") as? SKLabelNode)!' It is executed correctly the first time around. – Tom Mar 15 '17 at 21:37
  • Well if that is the line that crashes, it means that you have likely tried to forcefully unwrap the optional whose underlying value is nil. – Whirlwind Mar 15 '17 at 21:44

0 Answers0