0

my game is about stories, you make choices and it will lead you to other screen like a novel in which you are the hero, I realised I need a save system, I want to save the last screen a player was on and load it when he click on load button in main menu :

like this

I found the class FileHandle but I don't know how to link it with my gamescreens. How am I supposed to code "save the last screen the player is on" and "load the last screen the player was on"

Thanks for your knowledge sharing

2 Answers2

0

You should have a look at the libGDX wiki.

Specifically:

File Handling

and

Preferences

If you only need to save the last page the user was on, Preferences might be your best option. You can easily save primitive data types, such as the index of the last screen, or the title, or however you have your content set up.

Matthew Tory
  • 1,306
  • 2
  • 16
  • 30
  • I looked at it before your answer but it hasn't helped me, how am I supposed to do ? :/ Exemple: I have Screen1 class which is my first screen how can I save it and later load it ? – All be good Sep 30 '16 at 18:04
  • @Boxy Laze Give your each of your screens a name or a number. When you load a screen, you can do preferences.putInt("currentScreen", screenName);. Then when you reopen your game, in the create() method, do preferences.get("currentScreen") and set the screen from the name you get. – Matthew Tory Sep 30 '16 at 23:32
  • Hi, thanks for your time, how am I sure the machine will load the last screen ? – All be good Oct 01 '16 at 06:53
0

use the Preference to save the game state in libgdx . which will store the data in devices internal memory. by using the preference you can save anything say example the score of the player. I have answered for the same kind of question in below link .please go through it once. I hope you will get the solution. Creating an Android save file on the local storage of the device?

Community
  • 1
  • 1