问题
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