此问题与Swift: SKSpriteKit, using Storyboards, UIViewController and UIButton to set in game parameters?有关,并使用相同的M.W.E. (链接如下)。
虽然这个故事板允许一个人通过点击从左到右进展:
play - > (简单/困难) - > GameScene
UIViewController
- > MyUIViewController
- > GameViewController
并点击上一个UIButton
上的UIViewController
并使用UILabel
说明"得分"从右到左,没有办法从{到使用"分数" {1}}到最后GameViewController
UIViewController
。
鉴于在UILabel
期间发生某个事件,我如何从GameScene
传递一些信息(例如分数)并转换到最后一个GameScene
,以便用户可以再次开始游戏。除了删除UIViewController
中的所有内容之外,还要删除GameViewController
的无法访问的旧实例。
对于某些条件,让它在M.W.E中点击紫色精灵。对于这些信息,让它变得微不足道,比如直到精灵被按下的时间,甚至只是一个随机数。
我的回答here - 并在此处实施StackOverflow SKSpriteKit with Menu - 表明这显然是可行的,但将所有内容降级为GameScene
而不是使用SKView
。如果可能的话,请保留与使用此混合storyboard
- storyboard
方法相关的答案以及如何让SKView
调用"得分" - {{1} }。
答案 0 :(得分:1)
您可以使用下一个场景的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)")
}