【问题标题】:Change the initial scene in spritekit swift 3更改 spritekit swift 3 中的初始场景
【发布时间】:2017-03-07 18:57:42
【问题描述】:

如何在新的 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。接下来是什么?

谢谢!!!!

【问题讨论】:

    标签: ios swift sprite-kit skscene


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多