我有一个名为IntroLayer的课程,我试图在我的游戏启动时加载为初始场景。但是,按照这些简单的步骤简单地将GameScene更改为IntroScene后,我的IntroScene就没有被加载。我设置了断点,如果让场景看到它跳过它,甚至在实际的IntroScene中设置断点来验证未调用didMoveToView。有什么想法吗?
我在GameViewController中将let场景从GameScene更改为IntroScene,如下所示:
import UIKit
import SpriteKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let scene = IntroScene(fileNamed:"IntroScene") {
// 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)
}
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return .AllButUpsideDown
} else {
return .All
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
然后将GameScene.swift重命名为IntroScene.swift并将类更改为:
import SpriteKit
class IntroScene: SKScene {
override func didMoveToView(view: SKView) {
backgroundColor = UIColor.blackColor()
let fadeIn:SKAction = SKAction.fadeInWithDuration(1.0)
let fadeOut:SKAction = SKAction.fadeOutWithDuration(1.0)
let inspiredText = SKLabelNode(fontNamed: "Dead Kansas")
inspiredText.alpha = 0.0
inspiredText.text = "Inspired By"
inspiredText.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
addChild(inspiredText)
inspiredText.runAction(fadeIn)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch in touches {
// let location = touch.locationInNode(self)
}
}
}
然而,当我启动应用程序时,似乎在设置断点时甚至没有调用IntroScene,而且我的屏幕背景为灰色。
答案 0 :(得分:1)
您需要将GameScene.sks重命名为IntroScene.sks
sks文件是场景数据的归档文件,如果你打开它,你会发现你可以改变场景的很多东西,甚至可以直接添加节点和精灵。当您致电if let scene = IntroScene(fileNamed:"IntroScene") {
时,您正在取消将sks文件作为场景加载,因此无论何时您想要创建新场景,请记住您需要此文件。