在Spritekit中更改初始场景 [英] Changing the initial scene in spritekit
问题描述
目标:
要将场景加载到Instructions1.swift文件中作为游戏的第一个场景.
To load the scene in Instructions1.swift file as the first scene of the game.
我做了什么:
所以我在项目中创建了2个新文件:Instructions1.sks和Instructions1.swift
So I created 2 new files in my project : Instructions1.sks and Instructions1.swift
然后在GameViewController.swift中,我如下更改viewDidLoad:
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)
}
}
但是,当我加载游戏时,它会直接进入GameScene.swift.我还为"Instructions1.sks"在自定义类"下编写了"Instructions1".不幸的是,仍然没有运气!
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!
非常感谢您的帮助!
谢谢!
推荐答案
您应更改要加载的场景的名称.从文件加载SKScene时,还可以使用 init(fileNamed:)初始化程序.
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.
希望这会有所帮助!
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)
}
}
这篇关于在Spritekit中更改初始场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!