0

I'm now at a point where I need to save the current game state. I'm using libGDX and did add the kryo lib to my project and did some testings.

Question:

  • Do I have to override the file every save or can I override only the bites that change from one class.

  • Do I have to create allways a new OutputStream if I whant the game to be saved? (Save game every 5 mins for example)

  • I whant the current entities that are created to be saved should I create one file for all or for each entity a file?

1 Answers1

0

Dario,

Do I have to override the file every save or can I override only the bites that change from one class.

You don't have to, but should (create a fresh save file on every save). There is no reason to overcomplicate this.

Do I have to create allways a new OutputStream if I whant the game to be saved? (Save game every 5 mins for example)

Again, why worry? You save once per 5 minutes, you won't notice any difference (besides your coding time and efforts being wasted) if you reused your OutputStream or created a new one. Create a new one.

I whant the current entities that are created to be saved should I create one file for all or for each entity a file?

Depends on what makes sense and what these "entities" are. In any case to save the entity you will need to serialize it, which is just a fancy way of saying create a representation of it in text. To load the entity, reverse the process (deserialize it). The easiest way to learn how to do this is to make a JSONObject (library here). Put the values from the entity into the JSONObject and to turn it into text, call JSONObject.toString(). To deserialize it, create a new JSONObject and pass the text into its constructor. You may then retrieve the values.

WonderfulWorld
  • 439
  • 4
  • 11
  • These entities could be 3 types: Enemies max 15, Projectiles max 50, Blocks (Triangles that are destructable but grow back after time ) They have to grow back allso if they're not in the vilible area (only visible areas of the map will be loaded) –  Jun 07 '16 at 07:45
  • Save it into 1 file as described. – WonderfulWorld Jun 07 '16 at 12:35