Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android saving game state

I'm developing a game and i've ran into some questions about saving and resuming the game. Let's say i have 10 animated sprites drawn every frame (which move side to side) and everytime i press the home button or back button and then go back to my game, it starts drawing the sprites at the starting position rather than in the position before the back/menu press.

  • Do i have to save every sprite and animation position in order to achive resuming the game where i left off (using Bundle, onSaveInstanceState and onRestoreInstanceState())? Or can this be achived some other simpler way.I'm using the lunarlander example.

Thanks for the reply's.

Regards, J.

like image 480
Jernej Avatar asked Nov 14 '22 22:11

Jernej


1 Answers

Be sure to check this link: Data Storage

You can't store your data using Bundle, cause Bundle is storing data only when the application is running, so when your application is destroyed all information from Bundle will be lost. The way that I'm using is Shared Preferences, it's a simple and comfortable way to solve your problem. You can read more about this following the link above. Hope this was helpful to you. Good luck!

like image 97
Egor Avatar answered Dec 15 '22 04:12

Egor