【发布时间】:2015-09-14 15:14:18
【问题描述】:
我的项目是作为Spritekit 游戏开始的。
我在情节提要中的defaultviewcontroller 顶部放置了一个按钮。
我已经在viewwilllayoutsubviews中展示了一个场景。
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as! SKView
self.skView = 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 = SKSceneScaleMode.AspectFill
println("Width: \(scene.frame.width) andHEight: \(scene.frame.height)")
scene.gameSceneDelegate = self
sceneStack.append(scene)
skView.presentScene(scene)
}
一段时间后,我通过视图控制器代码转换到了一个新场景:
skView.presentScene(scene, transition: transition)
现在场景发生了变化,但我放在视图情节提要上的按钮仍然保留在场景顶部。
在第二个场景中,我像这样更改 UIButton 的图像:
self.lockButton.setImage(UIImage(named: "unlocked-button"), forState: UIControlState.Normal)
现在按下按钮时,我会更改按钮的图像。这令人惊讶地导致场景变回之前的场景。 因此,更改按钮的任何属性都会导致我的新场景弹出并恢复到我最初呈现的场景。
总结: 简而言之,我想要的是一个 UIViewController,它将在我的游戏的每个场景中都有一个通用的 HUD。结果,我不断更改 UIViewController 呈现的场景,保持 UIViewController 不变。但是,当我更改按钮的任何属性时,通过情节提要设置,显示在 SKScene(图像、背景图像、标题等)上,它会导致视图恢复到它显示的初始场景。
【问题讨论】:
-
如果您粘贴按钮的代码会有所帮助
-
我的错,问题已被编辑以详细说明。
标签: ios swift sprite-kit