如何更改新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.sk,并希望将这些场景设置为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
}
}