Save game state after pause. AndEngine

后端 未结 1 2031
执笔经年
执笔经年 2021-02-10 20:51

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. <

相关标签:
1条回答
  • 2021-02-10 21:29

    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.

    0 讨论(0)
提交回复
热议问题