如何在新的 xcode3 中更改初始场景?我找到了很多说明,但所有说明都适用于此代码:
extension SKNode {
class func unarchiveFromFile(file : String) -> SKNode? {
if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") {
var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)!
var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)
archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! MenuScene
archiver.finishDecoding()
return scene
} else {
return nil
}
}
但是新的 Xcode 项目,GameViewController 不包含这部分代码,当我尝试复制时,它不起作用。所以我制作了 MainScene.swift 和 MainScene.sks 并想将这些场景设置为 main。接下来是什么?
谢谢!!!!
最佳答案
如果您为场景布局使用 .sks 文件,请使用以下代码。
override func viewDidLoad() {
super.viewDidLoad()
if let view = self.view as! SKView? {
// Load the SKScene from 'MainScene.sks'
if let mainScene = MainScene(fileNamed: "MainScene") {
// Set the scale mode to scale to fit the window
mainScene.scaleMode = .aspectFill
// Present the scene
view.presentScene(mainScene)
}
view.showsFPS = true
view.showsDrawCount = true
view.showsNodeCount = true
view.showsPhysics = true
view.showsDrawCount = true
}
}
关于ios - 更改 spritekit swift 3 中的初始场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42656119/