gpt4 book ai didi

xcode - 更改默认 SKScene

转载 作者:行者123 更新时间:2023-11-28 06:56:48 25 4
gpt4 key购买 nike

我有一个名为 IntroLayer 的类,我试图在启动游戏时将其加载为初始场景。但是,按照这些简单步骤中的描述,简单地将 GameScene 更改为 IntroScene 后,我的 IntroScene 没有被加载。我在 if let 场景上设置断点以查看它是否跳过它,甚至在实际的 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,而且我的屏幕背景为灰色。

最佳答案

您需要将 GameScene.sks 重命名为 IntroScene.sks

sks文件是场景数据的存档文件,如果你打开它,你会发现你可以改变场景的很多东西,甚至可以直接向其中添加节点和 Sprite 。当您调用 if let scene = IntroScene(fileNamed:"IntroScene") { 时,您正在取消归档 sks 文件以作为场景加载,因此无论何时您想要创建一个新场景,请记住您将需要这个文件。

关于xcode - 更改默认 SKScene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33374085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com