保存玩家数据和状态 [英] Saving player data and status

查看:98
本文介绍了保存玩家数据和状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个Android游戏,我想知道如何保存玩家的数据,例如金钱,达到的等级等.我认为XML并不是实现此目的的真正方便的方法.有什么好办法吗? android是否提供某种保存数据的方法?

I made an android game and I want to know how to save player data such as money, level reached, etc. I think that XML is not a really convenient way to do this. Is there any good way to do this? Does android provide some method to save the data?

推荐答案

对于您需要跟踪的数据类型,数据库可能是过大的.我建议使用Android的SharedPreferences API. 请参阅此处以获取教程.

A database is probably overkill for the type of data you need to track. I would suggest using Android's SharedPreferences APIs. See here for a tutorial.

这是 Android数据持久性方法的官方概述,其中包括SharedPreferences和SQLite.

Here's an official overview of Android data persistence methods including SharedPreferences and SQLite.

检出

Check out the getStringSet API for storage of arrays/collections.

对于字符串集不存在的val:

For non-existent vals for the string set:

返回首选项值,如果它们 存在或defValues.投掷 ClassCastException如果存在 这个名字不是 一组.

Returns the preference values if they exist, or defValues. Throws ClassCastException if there is a preference with this name that is not a Set.

对于不存在的值数据,例如字符串,布尔值,浮点数等:

For non-existent value data such as string, bool, float etc.:

返回首选项值(如果有) 存在或defValue.投掷 ClassCastException如果存在 这个名字不是 字符串.

Returns the preference value if it exists, or defValue. Throws ClassCastException if there is a preference with this name that is not a String.

这篇关于保存玩家数据和状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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