我有一个名为IntroLayer的类,当我的游戏启动时,我正尝试将其作为初始场景加载。但是,按照这些简单步骤中的描述,简单地将GameScene更改为IntroScene之后,不会加载我的IntroScene。我在if场景上设置了断点,以确保它跳过它,甚至在实际的IntroScene中设置断点来验证didMoveToView没有被调用。有什么想法吗?
I将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,而且我得到的屏幕有灰色背景。
发布于 2015-10-27 17:22:57
您需要将您的GameScene.sks重命名为IntroScene.sks
sks文件是您的场景数据的存档文件,如果您打开它,您会注意到您可以更改有关场景的许多内容,甚至可以直接向其添加节点和精灵。当您调用if let scene = IntroScene(fileNamed:"IntroScene") {时,您要将sks文件解压缩为一个场景,因此,每当您想要创建一个新场景时,请记住您将需要这个文件。
https://stackoverflow.com/questions/33374085
复制相似问题