问题
Aim:
To load the scene in Instructions1.swift file as the first scene of the game.
What I did :
So I created 2 new files in my project : Instructions1.sks and Instructions1.swift
Then in GameViewController.swift , I changed the viewDidLoad as follows :
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)
}
}
However when I load the game, it goes straight to GameScene.swift. I also wrote 'Instructions1' under the Custom Class for Instructions1.sks . Still no luck unfortunately!
Would appreciate any help!
Thanks!
回答1:
You should change the name of the scene that you're loading up. Also using the init(fileNamed:) initializer is a go-to for me when loading a SKScene from a file.
Hopefully this helps!
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)
}
}
来源:https://stackoverflow.com/questions/36876376/changing-the-initial-scene-in-spritekit