我正在制作一款 50 多个关卡的游戏。我似乎无法保存游戏,以便当用户稍后打开游戏时,它将处于用户离开时的同一级别。我使用以下代码从一个级别转换到另一个级别。
let leveltwo = levelTwo(fileNamed: "levelTwo")
leveltwo?.scaleMode = .aspectFill
self.view?.presentScene(leveltwo!, transition:SKTransition.fade(withDuration: 0.1))
我还有每个级别的“example.swift”和“example.sks”文件。我的目标是保存用户所在的级别。我没有保存高分,我知道该怎么做。但我不确定是否相同。或者我如何应用它。
您可能想使用用户默认值 https://developer.apple.com/documentation/foundation/userdefaults.
所以,举例来说,在你的AppDelegate
你会实现这个:
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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)