如何在精灵套件项目中设置初始场景?

时间:2015-07-22 16:58:31

标签: ios swift sprite-kit skscene

我有两个SKScenes MenuSceneGameScene,我打开应用时出现的默认场景是import UIKit import SpriteKit 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 } } } class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() if let scene = MenuScene.unarchiveFromFile("MenuScene") as? MenuScene { // Configure the view. let skView = self.view as! SKView skView.showsFPS = true skView.showsNodeCount = true /* Sprite Kit applies additional optimizations to improve rendering performance */ skView.ignoresSiblingOrder = true /* Set the scale mode to scale to fit the window */ scene.scaleMode = .AspectFill skView.presentScene(scene) } } ,但我希望MenuScene首先出现

我尝试更改GameViewController中的代码:

Scanner input = new Scanner(System.in);
input.useDelimiter("\n")
System.out.println(input.next());
System.out.println("end");

但它只显示灰色屏幕而非场景,我还需要制作其他东西吗?

1 个答案:

答案 0 :(得分:0)

是您的MenuScenesks文件?可能不是,你只需要swift文件作为场景。

如果我理解正确,unarchiver将获取sks文件并取消归档,查看“unarchiveFromFile”方法,查看if语句,else返回nil。

你可能会这样做:

if let scene = new MenuScene() {

而不是unarchive。否则,请生成sks文件的MenuScene版本。