如何在加载SKScene时切换到UIViewController,反之亦然?到目前为止,我已经能够实现NSNotificationCenter来告诉我的GameViewController切换,但我遇到了运行什么代码来实际更改场景的问题。这是我的GameViewController.swift文件:
import UIKit
import SpriteKit
import StoreKit
class GameViewController: UIViewController {
override func viewDidLoad() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "openArtboard:", name:"OpenArtboard", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "openHomeScreen:", name:"OpenHomeScreen", object: nil)
//Load the initial home screen
let scene = homeScreen(size: view.bounds.size)
let skView = view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = false
scene.scaleMode = .ResizeFill
skView.presentScene(homeScreen(size: skView.bounds.size))
}
func openArtboard(NSNotificationCenter) {
//Dont know what to put here
}
func openHomeScreen(NSNotificationCenter) {
//Dont know what to put here
}
}
非常感谢任何帮助。
答案 0 :(得分:-1)
我没有时间测试这些答案,但要试用它们。
请记住,UIViewController包含SKView,因此通过更改当前视图控制器,您也将删除当前的SKView。 尝试使用segue转到另一个SKView。
如何从viewcontroller加载场景?它已存在于您的代码中:
let scene = homeScreen(size: view.bounds.size)
let skView = view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = false
scene.scaleMode = .ResizeFill
skView.presentScene(homeScreen(size: skView.bounds.size))