2017-03-07 10 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 
    } 
} 
関連する問題