共享首选项和 highschore/级别选择
我试图在启动游戏之前创建一个级别选择/高分屏幕。布局设置为 2 列视图,级别 # 和高分作为单独的文本视图。我能够使用数据建立此设置并手动填充,但似乎无法使用首选项来完成它。我应该为此烦恼还是跳过它并采用数据库方法? (大约有 60 个关卡,只记录最高分)
这个组合有什么帮助吗?可能是我对偏好的理解不够,但我还没有找到任何代码或解释似乎与我以及我想要完成的任务产生共鸣。
I'm trying to create a level select / high-score screen before launching a game. The layout is set to be a 2 column view, with the level # and the high-score as individual textviews. I'm able to establish this setup with data and populate manually but cannot seem to accomplish it using preferences. Should I bother with this or skip it and go for a database approach? (will be ~60 levels, only keeping track of the highest high-score)
Any help with this combination? It may be that I don't understand the preferences enough but I haven't found any code or explanations that seem to resonate with me and what I'm trying to accomplish.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想存储最高分数和达到该分数的级别编号,SharedPreferences 就很好,而且更容易处理。
如果您只有很少且非常简单的数据,那么 SharedPreference 是存储它们的正确位置......
If you just want to store the highest score and the level number where you reached it, SharedPreferences is fine and much easier to handle.
If you have only few and very simple data, than SharedPreference is the right place to store them...
共享偏好将比走数据库路线容易得多。由于要存储的内容很少,因此应该轻而易举。查看简单的 Google 示例。
Shared preferences are going to be a lot easier than going the DB route. With so little to store, it should be a breeze. Check out the simple google example.