Salve o estado do jogo após a pausa.Andengine
Pergunta
Eu descobri que depois de retomar o jogo todo o motor é recarregado e o aplicativo é reinicializado. Eu quero salvar o estado do motor e em "ONResume" retomar o processo de proccesso do jogo.
Eu tentei salvar todo o motor (Mengine) e depois retomar o jogo no mecanismo salvo "onloadEngine".Eu acho que é uma solução ruim e não funciona
Qual é a melhor solução para pausa \ retomar o jogo (após a chave de energia pressionada por exemplo) no Andengine?
Solução
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.