I want to use AssetManager in LibGDX to load my TextureAtlas. But I am not getting it. I have actually one large 2048 x 2048 px image, that I am creating in Predator. and then I am using the regions. Should I need to load the atlas once using AssetManager or what?
This is my current code
public class Assets {
private final static String FILE_SPRITE_ATLAS = "data/sprite_sheet.txt";
private final static String FILE_UI_SKIN = "skin/uiskin.json";
private final static String FILE_UI_SKIN_OTHER = "otherskin/uiskin.json";
public static TextureAtlas spriteAtlas;
public static Skin skin;
public static Skin other_skin;
//
public static TextureRegion bg;
public static TextureRegion dark_bg;
public static TextureRegion button_bg;
public static TextureRegion dracus;
public static TextureRegion egg;
public static TextureRegion egg_icon,play_icon,settings_icon,fb_icon,back_icon,credits_icon,sound_off,sound_on;
public static TextureRegion hunter_shooting;
public static TextureRegion hunter_walking;
public static TextureRegion button_pause;
public static TextureRegion dragon_icon;
public static TextureRegion arrow;
public static TextureRegion transparent_credits;
public static TextureRegion transparent_box;
public static TextureRegion transparent,mat,high_scores,tooltip,player_icon;
public static TextureRegion logo,egg_bucket,audio_icon,lock_icon,star;
public static Animation dragonLeft, dragonRight,dragonUp,dragonFront;
public static Animation anim_hunter_shooting;
public static Animation anim_hunter_walking;
public static Animation hunter_ready_shooting;
//
public static BitmapFont smallFont;
public static BitmapFont bigFont;
// TEST OBJECT
public static TextureRegion imgTest;
public static BitmapFont font3_1;
public static Texture loadTexture(String file) {
return new Texture(Gdx.files.internal(file));
}
public static TextureAtlas getSpriteAtlas() {
if (spriteAtlas == null) {
spriteAtlas = new TextureAtlas(
Gdx.files.internal(FILE_SPRITE_ATLAS));
}
return spriteAtlas;
}
public static Skin getSkin() {
if (skin == null) {
FileHandle skinFile = Gdx.files.internal(FILE_UI_SKIN);
skin = new Skin(skinFile);
}
return skin;
}
public static Skin getOtherSkin() {
if (other_skin == null) {
FileHandle skinFile = Gdx.files.internal(FILE_UI_SKIN_OTHER);
other_skin = new Skin(skinFile);
}
return other_skin;
}
public static void loadAll() {
relaseResources();
loadImages();
loadButtons();
loadFonts();
loadAnimations();
loadSoundsAndMusics();
}
private static void relaseResources() {
skin = null;
}
public static void loadImages() {
//REGIONS FROM SPRITE ATLAS
bg = getSpriteAtlas().findRegion("bg");
dark_bg = new TextureRegion(bg.getTexture(),0,0,960,300);
button_bg = getSpriteAtlas().findRegion("button_bg");
dracus = getSpriteAtlas().findRegion("dracus");
egg = getSpriteAtlas().findRegion("egg");
egg_icon = getSpriteAtlas().findRegion("egg_icon");
sound_on = getSpriteAtlas().findRegion("sound_on");
sound_off = getSpriteAtlas().findRegion("sound_off");
credits_icon = getSpriteAtlas().findRegion("credits_icon");
back_icon = getSpriteAtlas().findRegion("back");
fb_icon = getSpriteAtlas().findRegion("fb_icon");
settings_icon = getSpriteAtlas().findRegion("settings_icon");
play_icon = getSpriteAtlas().findRegion("play_icon");
transparent = getSpriteAtlas().findRegion("transparent");
hunter_walking =getSpriteAtlas().findRegion("hunter_walking");
hunter_shooting =getSpriteAtlas().findRegion("hunter_shooting");
button_pause =getSpriteAtlas().findRegion("button_pause");
arrow =getSpriteAtlas().findRegion("arrow");
dragon_icon =getSpriteAtlas().findRegion("dragon_icon");
transparent_credits =getSpriteAtlas().findRegion("transparent_credits");
transparent_box =getSpriteAtlas().findRegion("transparent_box");
egg_bucket =getSpriteAtlas().findRegion("egg_bucket");
logo =getSpriteAtlas().findRegion("logo");
mat =getSpriteAtlas().findRegion("mat");
audio_icon=getSpriteAtlas().findRegion("audio_icon");
lock_icon =getSpriteAtlas().findRegion("lock_icon");
//howtoplay_icon =getSpriteAtlas().findRegion("howtoplay_icon");
high_scores =getSpriteAtlas().findRegion("high_scores");
star = getSpriteAtlas().findRegion("star");
tooltip = getSpriteAtlas().findRegion("tooltip");
player_icon = getSpriteAtlas().findRegion("player_icon");
}
public static void loadButtons() {
//img_btn_home = getAtlas().findRegion("img_btn_home");
//img_btn_home_pressed = getAtlas().findRegion("img_btn_home_pressed");
}
public static void loadFonts() {
//
smallFont = new BitmapFont(Gdx.files.internal("data/smallFont.fnt"),
Gdx.files.internal("data/smallFont.png"), false);
bigFont = new BitmapFont(Gdx.files.internal("data/bigFont.fnt"),
Gdx.files.internal("data/bigFont.png"), false);
font3_1 = new BitmapFont(Gdx.files.internal("data/font3.fnt"),
Gdx.files.internal("data/font3.png"), false);
}
public static void loadAnimations() {
//Loading the Dragon
TextureRegion[][] regions2 = Assets.dracus.split(96, 96);
dragonLeft = new Animation(0.15f, regions2[1][0],regions2[1][1], regions2[1][2],regions2[1][3]);
dragonLeft.setPlayMode(Animation.LOOP_PINGPONG);
dragonRight = new Animation(0.15f, regions2[2][0],regions2[2][1], regions2[2][2],regions2[2][3]);
dragonRight.setPlayMode(Animation.LOOP_PINGPONG);
dragonUp = new Animation(0.15f, regions2[3][0],regions2[3][1], regions2[3][2],regions2[3][3]);
dragonUp.setPlayMode(Animation.LOOP_PINGPONG);
dragonFront = new Animation(0.15f, regions2[0][0],regions2[0][1], regions2[0][2],regions2[0][3]);
dragonFront.setPlayMode(Animation.LOOP_PINGPONG);
TextureRegion[][] hunter_shoot_regions = hunter_shooting.split(110, 143);
anim_hunter_shooting = new Animation(0.25f, hunter_shoot_regions[0][0],hunter_shoot_regions[0][1],
hunter_shoot_regions[0][2],hunter_shoot_regions[0][3]);
//anim_hunter_shooting.setPlayMode(Animation.LOOP_PINGPONG);
hunter_ready_shooting = new Animation(1.0f, hunter_shoot_regions[0][0],hunter_shoot_regions[0][1]);
TextureRegion[][] hunter_walk_regions = hunter_walking.split(86, 132);
anim_hunter_walking = new Animation(0.20f, hunter_walk_regions[0][0],hunter_walk_regions[0][1],
hunter_walk_regions[0][2],hunter_walk_regions[0][3]);
anim_hunter_walking.setPlayMode(Animation.LOOP_PINGPONG);
}
public static void loadSoundsAndMusics() {
}
}