LibGDX Asset loading

Hi guys,

I am working on small project with LibGDX at the moment and implemented my asset loading in a way I personally think is very convenient.
So I would like to know what you think of my implementation.
Is this a good way? Do you have a better way? Do I make some fatal mistakes here?
I don’t look for any micro optimizations, but anything that makes programming easier is really appreciated.


public class Assets {

    private static final AssetManager assetManager = new AssetManager();

    private static HashMap<String, AssetFile> files;

    /**
    * Enter all files from the assets folder in here
    */
    public static void load(){

        files = new HashMap<String, AssetFile>();

        //TextureAtlases
        files.put("backgroundTextureAtlas", new AssetFile("sprites/background.atlas",   TextureAtlas.class));
        files.put("entitiesTextureAtlas",   new AssetFile("sprites/entities.atlas",     TextureAtlas.class));
        files.put("uiTextureAtlas",         new AssetFile("sprites/ui.atlas",           TextureAtlas.class));
        
        //Skins
        files.put("defaultSkin",            new AssetFile("skins/default/uiskin.json",          Skin.class));
        files.put("pixthulhuSkin",          new AssetFile("skins/pixthulhu/pixthulhu-ui.json",  Skin.class));
        
        //I18Ns
        files.put("defaultI18N",            new AssetFile("i18N/prototype",             I18NBundle.class));

        //Loading files
        for(AssetFile asset : files.values()){
            assetManager.load(asset.path, asset.type);
        }

        assetManager.finishLoading();
        //while(!assetManager.update()){} TODO: Decide for one method
    }

    public static Object get(String hashmapKey){
        return assetManager.get(files.get(hashmapKey).path, files.get(hashmapKey).type);
    }

    public static void dispose(){
        assetManager.dispose();
    }
}

Later I get the sprites like this:


TextureAtlas textureAtlas = (TextureAtlas) Assets.get("entitiesTextureAtlas");
TextureRegion cityTexture = textureAtlas.findRegion("city");

Thank you in advance :slight_smile: