Swift: returning to Main Menu after condition is met in GameScene using StoryBoards and UIViewControllers?

前端 未结 1 538
庸人自扰
庸人自扰 2021-01-15 12:13

Context

This question is related to Swift: SKSpriteKit, using Storyboards, UIViewController and UIButton to set in game parameters? and uses the same M.W.E. (link b

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-15 12:59

    You could use the userData instance property of your next scene to store the current scene, something like:

    nextScene.userData = NSMutableDictionary()
    nextScene.userData?.setObject(actualScore, forKey: "actualScore" as NSCopying)
    

    and when you are in the next scene you can ask to this NSMutableDictionary who is the previous scene as:

    if let actualScore = self.userData?.value(forKey: "actualScore") {
        print("well done!, the score was: \(actualScore)")
    }
    

    0 讨论(0)
提交回复
热议问题