Search code examples
libgdx

Best way to store character info


I am creating a simple 2D game. I have player character and enemies that spawn each level. Every level has its own set of enemies with count of 1-6. Player character can level up into various classes - meaning that every class has its own textures. What is the best way to store data about player character (player textures, attributes) How to tell the game how to position enemies (different layout on different number of enemies)

I read about JSON, but apparently it is to slow, if you have big amount of data (I am not sure if my case is slow in that way). In my case there is about 30 different player paths and many many more different cases of enemy positions.


Solution

  • To store textures, sounds, tiled maps, fonts, etc. Use AssetManager class. It loads textures and other resources excellent in real time (Without loosing FPS). Also you can unload resources if they aren't need anymore. And load them again when there is a need.

    JSON isn't that slow how you describe. Store only data that is unique for every entity. For example zombie enemies:

    {
    "zombie" {"x": 100, "y": 10},
    "zombie" {"x": 100, "y": 20},
    }
    

    Other data can be declared in class.

    class Zombie {
    
       int width;
       int height;
       Texture texture;
    
       int x; // initialize later, when load from JSON
       int y;
    
       public Zombie(Texture texture, int width, int, height){
           this.texture = texture;
           this.width = width;
           this.height = height;
       }
    

    }