我发现这种小而优雅的方式可以使用Swift在SpriteKit中切换两个(或者更多)场景:
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))
}
}
当前场景创建新场景并将其发送到其视图。但是,这样做会在每次转换时创建一个新的场景对象。从长远来看,这会导致内存泄漏吗?