2017-03-07 91 views
1

如何更改新xcode3中的初始场景?我发现很多的指令,但是这一切与此代码的工作:更改spritekit swift中的初始场景3

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。接下来是什么?

谢谢!

回答

2

如果您的场景布局使用.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 
    } 
}