I found this small and elegant way to switch between two (or probably more) scenes in SpriteKit using Swift:
class GameScene: SKScene {
override func didMove(to view: SKView) {
self.backgroundColor = SKColor.blue
//initialize the scene
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
let newScene = PrefScene()
newScene.scaleMode = .aspectFill
self.view?.presentScene(newScene, transition: SKTransition.crossFade(withDuration: 3))
}
}
The present scene creates the new scene and sends this to it's view. However, doing it this way creates a new scene object every time there's a transition. Will this lead to memory leakage in the long run?