I'm making a simple 2D game in libgdx, and now I'm at the point where I have to save data. I already have a mechanism to save the data itself. The problem is that I don't know when/where the procedure to save the state should be executed. Should it be executed in dispose method? Or pause method? Save the state every time the player dies doesn't seem very efficient to me. Anyone can give me tips about this? Thanks in advance.
1 Answer
Make sure the player never loses progress. That means saving when the player has achieved some sort of waypoint rather than when the game is exited or when the player returns to the main menu or something like that.
In the Pause method you're supposed to keep enough information to successfully recover after a Resume, this can be different from other saves where you save for example completion of a level.
In my games I try to save during the transition between levels. But this is of course different if you have the sort of game where the player has to reach a save-point.
Saving on every death doesn't seem like it's that often (unless you expect your players to die every second or so), but I wouldn't do it unless the death is part of the state that needs to be persisted. For example if they only got three lives to complete the game then you need to save on each death or users will be able to kill the game process when they die to get an unlimited number of lives.
The Android Design Principles (which, granted are more geared towards application development rather than game development), state that you should "Never lose my stuff".