I have a game where I have two scenes: FarmScene and WoodScene. Each scene has a .SKS file and a .swift file - one to design, and one to code. I've managed to move from FarmScene to WoodScene like this:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
let node : SKNode = self.atPoint(location)
if node.name == "WoodIcon" {
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
if let scene = SKScene(fileNamed: "WoodScene") {
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
view.presentScene(scene)
}
}
}
}
}
In my previous games I've used a SKTransition to move to different scenes, and with that I could do some cool transitions like flip, fade and push.
I was wondering if this is the "correct" way of changing scenes when using the scene designer in Xcode? Or maybe I'm missing something.
Looking forward to hear from you.