【发布时间】:2016-01-19 02:56:11
【问题描述】:
我有两个场景,GameScene 和 PlayScene。我可以展示我的 GameScene,但我不能展示 PlayScene,我使用的是相同的代码和正确的文件名。我使用 UIButton 来调用此函数。我什至试过不调用 showGameScene 只调用 goToPlayScene 还是不行。我正在使用 GameViewController 来呈现这两个场景。
func showGameScene()
{
if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = self.view as! SKView
/* 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)
}
}
func goToPlayScene()
{
playButton.hidden = true
Leaderboard.hidden = true
if let scene = PlayScene(fileNamed:"PlayScene")
{
let skView = self.view as! SKView
/* 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)
}
}
【问题讨论】:
-
您是否尝试在 skView.presentScene(scene) 处放置断点或在其后放置 print 语句?只是为了确保它实际上被调用
-
是的,我尝试了打印,但没有调用该语句。如果我不使用 if 语句并强制扭曲它,它会给我 nil。
-
等等,所以如果你只是在 skView.presentScene(scene) 之后放一个 print 语句并保持其他所有内容不变,那么 print 语句不会被调用?
-
这表明您的程序没有评估条件 (scene = PlayScene(fileNamed:"PlayScene") 为真。请确保您有一个名为 PlayScene 的文件。
-
好的,MailE 的回答应该会为您指明正确的方向
标签: ios iphone swift uiviewcontroller sprite-kit