如何保存当前级别 [英] how save the current level

查看:7
本文介绍了如何保存当前级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个有 50 多个关卡的游戏.我似乎无法保存游戏,因此当用户稍后打开游戏时,它将与用户离开时处于同一级别.我使用休闲代码从一个级别转换到另一个级别.

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. I use the fallowing code to transition from level to level.

let leveltwo = levelTwo(fileNamed: "levelTwo")
leveltwo?.scaleMode = .aspectFill
self.view?.presentScene(leveltwo!, transition:SKTransition.fade(withDuration: 0.1)) 

我也有每个级别的example.swift"和example.sks"文件.我的目标是保存用户所在的级别.我没有保存高分,我知道该怎么做.但我不确定它是否相同.或者我如何应用它.

I also have a "example.swift" and "example.sks" file for each level. My goal is to save the level that the user is on. Im not saving a high score, I know how to do that. But i'm not sure if its the same. Or how I can apply that it this.

推荐答案

你可能想使用 用户默认值.

因此,例如,在您的 AppDelegate 中,您将实现:

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
}

这篇关于如何保存当前级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆