Save game state after pause. AndEngine

五迷三道 提交于 2019-12-04 13:32:50

问题


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 Pause\Resume the game (after power key pressed for example) in andEngine ?


回答1:


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.



来源:https://stackoverflow.com/questions/9020346/save-game-state-after-pause-andengine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!