更改spritekit中的初始场景

目标:

在Instructions1.swift文件中加载场景作为游戏的第一个场景。

我做了什么 :

所以我在我的项目中创build了2个新文件:Instructions1.sks和Instructions1.swift

然后在GameViewController.swift中,我改变了viewDidLoad,如下所示:

override func viewDidLoad() { super.viewDidLoad() if let scene = GameScene.unarchiveFromFile("Instructions1") as? GameScene { // 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) } } 

但是当我加载游戏时,直接进入GameScene.swift。 我还在Instructions1.sks的自定义类下编写了“Instructions1”。 遗憾的是还是没有运气

将不胜感激任何帮助!

谢谢!

你应该改变你正在加载的场景的名称。 当从文件加载SKScene时,也使用init(fileNamed 🙂初始值设定项是我的一个select。

希望这有助于!

 override func viewDidLoad() { super.viewDidLoad() if let scene = Instructions1(fileNamed:"Instructions1") { // 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) } }