Skip to content
Snippets Groups Projects

Resolve "Login screen setup (without backend)"

Merged Sander Østrem Fagernes requested to merge 19-login-screen-setup-without-backend into main
Compare and Show latest version
2 files
+ 20
15
Compare changes
  • Side-by-side
  • Inline
Files
2
package com.game.tankwars;
import com.badlogic.gdx.assets.AssetDescriptor;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader;
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.github.acanthite.gdx.graphics.g2d.FreeTypeSkinLoader;
/**
* A Singleton that manages all assets in application.
* It uses the LibGDX AssetManager, but encapsulates it to only expose necessary methods.
*
* The application uses scene2d.ui and loads Skin objects, each with a
* TextureAtlas and a JSON file.
*/
public class ResourceManager {
private static ResourceManager instance = null;
private final AssetManager manager;
private final AssetDescriptor<TextureAtlas> MENU_ATLAS =
new AssetDescriptor<>("menu-textures.atlas", TextureAtlas.class);
private final AssetDescriptor<Skin> MENU_SKIN =
new AssetDescriptor<>("menu-textures.json", Skin.class);
public ResourceManager() {
manager = new AssetManager();
manager.setLoader(Skin.class, new FreeTypeSkinLoader(manager.getFileHandleResolver()));
}
/**
* Singleton getter
* @return The ResourceManager instance
*/
public static ResourceManager getInstance() {
if (instance == null) instance = new ResourceManager();
return instance;
}
/**
* Loads the TextureAtlas and the Skin for the menus,
* and attaches the TextureAtlas to the Skin.
*
* @return loaded Skin object with JSON file and TextureRegions
* null on loading error
*/
public Skin loadAndGetMenuAssets() {
if (!manager.isLoaded(MENU_ATLAS)) manager.load(MENU_ATLAS);
if (!manager.isLoaded(MENU_SKIN)) manager.load(MENU_SKIN);
try {
manager.finishLoading();
manager.get(MENU_SKIN).addRegions(manager.get(MENU_ATLAS));
return manager.get(MENU_SKIN);
} catch(GdxRuntimeException error) {
System.out.println(error.getMessage());
}
return null;
}
/**
* Block until all currently loaded assets are finished loading
*/
public void finishLoading() {
manager.finishLoading();
}
/**
* Unload all currently loaded assets
*/
public void clear() {
manager.clear();
}
/**
* Dispose of the manager
*/
public void dispose() {
manager.dispose();
}
}
Loading