我正在使用Spritekit开发macOS游戏。想要使用第二个场景。如何设置App Delegate和ViewController来实现这一目标? 我可以转换到第二个场景
var secondScene = SecondScene(size: self.size)
var transition = SKTransition.flipVertical(withDuration: 1.0)
secondScene.scaleMode = SKSceneScaleMode.aspectFill
self.scene!.view?.presentScene(secondScene, transition: transition)
SecondScene中的类似代码在重新加载上一个场景时返回导致崩溃,第一次加载时会很好。
self.scene!.view?.presentScene(FirstScene, transition: transition)
这就是我的ViewController的样子。
类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
}
}
}