Skip to content

Commit

Permalink
Moved out font loading and changed to async loading using external as…
Browse files Browse the repository at this point in the history
…set manager
  • Loading branch information
basimkhajwal committed May 29, 2016
1 parent d2df9f0 commit 4b4c76b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions core/src/net/net63/codearcade/LSD/managers/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ public static class Animations {

public static final String UI_SKIN = "skin/uiskin.json";

private static AssetManager assetManager = new AssetManager();
private static AssetManager assetManager;

//Private constructor to prevent instantiation
private Assets () { }

/**
* Static method that loads all the assets in the asset classes
*/
public static void loadAll() {
public static void loadAll(AssetManager manager) {

assetManager = manager;

for (String image: _Images) assetManager.load(image, Texture.class);
for (String animation: _Animations) assetManager.load(animation, Texture.class);
Expand All @@ -120,9 +122,12 @@ public static void loadAll() {
}

assetManager.load(UI_SKIN, Skin.class);
}

assetManager.finishLoading();

/**
* Separate function to load fonts synchronously
*/
public static void loadFonts() {
//Load fonts separately
for (String fontName: _Fonts) {
ArrayMap<Integer, BitmapFont> localCache = new ArrayMap<Integer, BitmapFont>();
Expand All @@ -136,15 +141,21 @@ public static void loadAll() {

fontCache.put(fontName, localCache);
}
}

/**
* Handler to be called when the AssetManager finishes
* loading all the required assets
*/
public static void finishLoading() {
//Setup the animations
for (String animation: _Animations) {
TextureRegion texture = new TextureRegion(assetManager.get(animation, Texture.class));
TextureRegion[] regions = texture.split(24, 24)[0];

animationList.put(animation, new Animation(0.1f, regions));
}
}
}

/**
* Get a loaded asset of type T from the loaded cache
Expand Down

0 comments on commit 4b4c76b

Please sign in to comment.