I wonder how do I implement data persistence in 2d game. I am not using any engine, just pure Kotlin and OpenGL for rendering, so it is more of a software architecture question. The case:
Character travels on the tile map and after crossing the edge of it proceeds to the next level (or next map). Let's assume I want to store the character and its attributes, update actions (which are being performed in "update" method of the game), .
Of course I can store the character entity in some kind of an object, that will be passed from one "scene" to another. Possible cons: unnecessary additional code to store and pass object.
Using a file. Cons: This leads to parsing the file, opening streams to read data and etc.
Declaring entities as static objects. Cons: I am afraid this can cause memory leaks, I am not sure how I am going to dispose static objects.
Declare static object, which will hold the collection of data objects. Share it between all scenes. This seems like an optimal solution so far, even though I still will be referencing the object, I will have the ability to dispose certain entities.
I am not sure if some of the cons I mentioned are really making difference and will be significant. I want to know how this kind of logic is usually implemented.