繁体   English   中英

在Spritekit Swift 3中更改初始场景

[英]Change the initial scene in spritekit swift 3

如何在新的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
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM