SpaceFloat Asset Management
This post is a devlog about SpaceFloat, the FaSTeam's entry for the libGDXJam.

SpaceFloat Asset Management

SpaceFloat uses an instance of the AssetManager provided by libGDX to manage assets. This instance follow the lifecycle of the SpaceFloatGame instance and it is injected into the Screens as a dependence.

public class SpaceFloatGame extends Game {

	private AssetManager assetManager;

	public SpaceFloatGame() {
		assetManager = new AssetManager();
	}

	// ...

	@Override
	public void dispose() {
		assetManager.dispose();
	}
}

The Loading Screen

A fundamental use case of the asset manager is in the LoadingScreen. With this technique you can load all assets within a directory while showing progress.

public class LoadingScreen extends SpaceFloatScreen {
	private static final String TEXTURE_DIRECTORY = "textures/";
	private AssetManager assetManager;
	private float progress;

	@Override
	public void show() {
		super.show();
		assetManager = getAssetManager();
		FileHandle[] files = Gdx.files.local(TEXTURE_DIRECTORY).list();
		for(FileHandle file : files) {
			assetManager.load(file.path(), Texture.class);
		}
	}

	@Override
	public void render(float delta) {
		assetManager.update();
		progress = assetManager.getProgress();
		logger.info("Loading assets: " + progress);
		if (progress < 1.0f) return;
		SpaceFloat.GAME.setScreen(ScreenEnumerator.MAIN);
	}
}
4 January 2016