Swift:使用StoryBoards和UIViewControllers在GameScene中满足条件后返回主菜单?
上下文
此问题与Swift: SKSpriteKit, using Storyboards, UIViewController and UIButton to set in game parameters?相关,并使用相同的M.W.E. (下方链接)。Swift:使用StoryBoards和UIViewControllers在GameScene中满足条件后返回主菜单?
虽然这个故事板将允许人们从左至右通过点击进度:
游戏 - >(易/硬) - >GameScene
UIViewController
- >MyUIViewController
- >GameViewController
,由右点击最后UIViewController
上的UIButton
与UILabel
陈述“得分”,但没有办法从GameViewController
到最后的UIViewController
与“得分”UILabel
。
问题
鉴于GameScene
过程中发生的某些事件,我怎么能传递一些信息,从GameScene
(例如分)和过渡到最后的最后UIViewController
,使用户可以重新开始游戏。除了删除GameViewController
中的所有内容外,还有一些不可接近的GameScene
的旧实例。
对于某些条件,让我们点击M.W.E中的紫色精灵。对于这些信息,让它像是直到精灵被按下的时间一样简单,甚至只是一个随机数。
最低工作实例
注
我的答案here - 这里StackOverflow SKSpriteKit with Menu实现 - 表明,这是完全可能的,但贬谪一切SKView
真是让人不是使用storyboard
。因此,如果可能,请保留与使用此混合storyboard
- SKView
方法有关的答案,以及如何让GameScene
调用“Score” - UIViewController
。
你可以使用你的下一个场景的userData实例属性来存储当前场景,一样的东西:
nextScene.userData = NSMutableDictionary()
nextScene.userData?.setObject(actualScore, forKey: "actualScore" as NSCopying)
,当你在一个场景,你可以问这个的NSMutableDictionary谁是前一个场景如:
if let actualScore = self.userData?.value(forKey: "actualScore") {
print("well done!, the score was: \(actualScore)")
}
您是否熟悉委托模式?这是子视图与父母沟通的常用方式。这[SO帖子](http://stackoverflow.com/questions/39561177/how-can-i-indicate-a-view-which-has-created-with-uikit-from-a-skscene/39564948#39564948)显示了基本的想法并执行了放松的过程。委托协议可以扩展为包含一个评分属性,所以场景可以在值更改时通知它的ViewController。 –
@MarkBrownsword没有。我不是,你能否用这个M.W.E解释它:https://github.com/SumNeuron/StackOverflow-SKSpriteKit-with-Menu – SumNeuron