how save the current level

后端 未结 1 351
遥遥无期
遥遥无期 2021-01-27 14:47

I am making a game with 50+ levels. I can\'t seem to be able to save the game so that when the user later opens the game, it will be on the same level they the user left off at.

相关标签:
1条回答
  • 2021-01-27 15:18

    You may want to use UserDefaults.

    So, for example, in your AppDelegate you would implement this:

    func applicationDidEnterBackground(_ application: UIApplication) {
        UserDefaults.standard.set("level_file_path", forKey: "currentLevel")
    }
    
    func applicationDidBecomeActive(_ application: UIApplication) {
        let levelFilePath = UserDefaults.standard.string(forKey: "currentLevel")
    
        // load your file/level here
    }
    
    0 讨论(0)
提交回复
热议问题