保存游戏(Android 应用程序。)

发布于 2024-12-15 05:38:37 字数 387 浏览 3 评论 0原文

这是一个悬而未决的问题。

我正在为 Android 开发一个简单的游戏,我已经达到了让用户能够保存进度并稍后返回的地步。

由于我是初学者,我不确定从哪里开始,所以我希望你们中的一些人至少能提出一些建议。

有关游戏设置的一些信息:

所有动画都是通过画布在线程中完成的,并基于 30 毫秒循环交替存储位图帧。

一切都是对象,角色、背景只是对象的二维数组。并且每个对象一般都是通过hashmap来动态引用和创建的。

现在如何保存?我知道我可以暴力破解它,只需保存每个地图中每个对象的坐标和当前操作等等。

但有更好的方法吗?我简单地读到,在 python 中,有一种称为“pickle”的对象消毒方法,还有一种类似的方法,称为“kryo”。我的方向正确吗?

This is somewhat of an open question.

I'm in the process of developing a simple game for android and I've gotten to the point where I'm trying to enable thee user to save their progress and return later.

As i'm a beginner, I'm not exactly sure where to start, so I was hoping some of you might have at least some suggestions.

A little info on the setup of the game:

All animation is done in a thread through a canvas and alternation of stored bitmap frames based on a 30 ms loop.

Everything is an object, the characters, the background is simply a 2d array of objects. and each object is generally referenced and created dynamically through a hashmap.

Now how to save? I know I could brute force it, and simply save coordinates and current actions blah blah etc. etc. for each object in each map.

But is there a better way to do this? I've briefly read that in python there's a method of sterilizing objects called "pickle," and there is something similar called "kryo." Am I looking in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幻梦 2024-12-22 05:38:37

您应该研究一下 Java 序列化。它并不完美,也存在问题,但它是将复杂的对象树转换为可以保存到文件或数据库并在需要时加载回来的最安全、最快的方法。

另外,总是有可能通过 INSERT SQL 查询等来使用您自己的特定序列化。但是要非常小心,很容易错过您想要保存/恢复的部分内容。其中一个示例是将对象树转换为 XML 并将该 XML 保存为文件。有非常好的第 3 方库可以将对象映射到 XML 并用 Java 映射回来。

You should look into Java serialization. It's not perfect, it has problems, but it's the safest, quickest way to turn a complex tree of objects into something that you can save to a file or a db, and load it back when you need.

Else, there's always the possibility to use your own specific serialization using INSERT SQL queries, etc. But be very careful, it's easy to miss parts of what you want to save / restore. One example of that would be to turn your objects tree into XML and save that XML as a file. There are very good 3rd-party libs to map objects to XML and back in Java.

陌路黄昏 2024-12-22 05:38:37

嗯..这不是灭菌,而是序列化..这是一种编程技术。序列化也是您要使用的技术。

如果您使用预定义的方法或自己编写的方法并不重要,但唯一重要的是循环对象并将稍后重新加载所需的日期写入文件(或保存结构)。

无论如何,是的,你正在寻找正确的方法。

最好的方法是实现序列化接口。调用 serialize() 方法的每个对象都必须保存其数据,然后为其拥有的每个子对象调用 serialize() 方法。

Well.. That's not STERILIZATION, but SERIALIZATION.. Which is a programming technique. And serialization is also the technique you want to use.

Doesn't matter if you use a predefined method or something you write on your own, but the only thing that matters is to loop across the objects and write to the file (or saving structure) the date you need to be later reloaded.

Anyway yes, you're looking the right way.

The best way to do it is implementing a serialization interface. Each object for which the serialize() method is called must save it's data and then call the serialize() method for each child object it owns.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文