我发现,在恢复游戏后,所有引擎都被重新加载并且应用程序重新初始化。 我想拯救发动机状态,并在“onresume”恢复游戏proccess。

我已经尝试保存所有发动机(Mengine),然后在“OnloadEngine”退货发动机中恢复游戏后。我认为这是一个不好的解决方案,它不起作用

暂停\恢复游戏的最佳解决方案是什么?在Andengine in Andengine(例如按下电源键后)?

有帮助吗?

解决方案

The solution I found was to serialize the state of the engine as JSON and save it as shared storage. Its a lot of work, but it does save it. Since andengine is going to re-init your engine and textures after a pause, I think there are not many choices, unless you want to re-write some of andengine for your game. (which you can)

In my JSON I record the position type velocity etc of each sprite. The complexity of what gets saved depends on the complexity of your game. And then to each class I added a deserialize method that accepts the JSON as input.

As a footnote to that method, I cannot speak highly enough of the amazing GSON library for making that an easier task. http://code.google.com/p/google-gson/

But remeber when restoring the game, to set the restored state to paused so the user knows when the game will re-commence.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top