暂停后保存游戏状态.和引擎 [英] Save game state after pause. AndEngine

查看:27
本文介绍了暂停后保存游戏状态.和引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在恢复游戏后,所有引擎都会重新加载并重新初始化应用程序.我想保存引擎状态并在onResume"中恢复游戏过程.

我尝试保存所有引擎 (mEngine),然后在onLoadEngine"中恢复游戏后返回保存的引擎.我认为这是一个糟糕的解决方案,它不起作用

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

解决方案

我找到的解决方案是将引擎的状态序列化为 JSON 并将其保存为共享存储.它的工作量很大,但它确实节省了它.由于andengine会在暂停后重新初始化你的引擎和纹理,我认为没有太多选择,除非你想为你的游戏重新编写一些andengine.(你可以)

在我的 JSON 中,我记录了每个精灵的位置类型速度等.保存内容的复杂性取决于游戏的复杂性.然后我为每个类添加了一个反序列化方法,该方法接受 JSON 作为输入.

作为该方法的一个脚注,我不能高度评价令人惊叹的 GSON 库,因为它使任务变得更容易.http://code.google.com/p/google-gson/>

但请记住,在恢复游戏时,将恢复状态设置为暂停,以便用户知道游戏何时重新开始.

i've found that after resuming the game all the engine is reloaded and application is reinitialized. I want to save engine state and in "onResume" resume the game proccess.

I've tried to save all the engine (mEngine) and then after resume the game in "onLoadEngine" return saved engine. I think it is a bad solution and it doesn't work

What is the best solution for PauseResume the game (after power key pressed for example) 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.

这篇关于暂停后保存游戏状态.和引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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