I create a Assets class
public class Assets {
public static final String TAG = "Assets";
public static AssetManager manager;
public static TextureAtlas textureAtlas;
public static void create() {
AbsoluteFileHandleResolver fileHandleResolver = new AbsoluteFileHandleResolver();
manager = new AssetManager(fileHandleResolver);
manager.setLoader(TextureAtlas.class, new TextureAtlasLoader(fileHandleResolver));
load();
}
private static void load() {
//This could be anywhere else
String fileName = Constant.ALL_COMPONENTS_PATH + "/skeleton.atlas";
if (!new FileHandle(fileName).exists()) {
Gdx.app.error(TAG, "invalid file '" + fileName + "'");
Gdx.app.exit();
}
if (!manager.isLoaded(fileName, TextureAtlas.class))
manager.load(fileName, TextureAtlas.class);
manager.finishLoading();
if (manager.isLoaded(fileName, TextureAtlas.class))
Gdx.app.log(TAG, "Texture loaded!");
else
Gdx.app.log(TAG, "Texture not loaded!");
}
public static TextureAtlas getTextureAtlas() {
return textureAtlas;
}
public static void dispose() {
LogUtils.d("assets dispose");
manager.dispose();
}
}
I extends AndroidFragmentApplication for my Fragment
And new a class extends to ApplicationAdapter
on the create method
Assets.create();
atlas = Assets.manager.get(Constant.ALL_COMPONENTS_PATH + "/skeleton.atlas", TextureAtlas.class);
First Time it works
but When I use it in other fragment like this
atlas = Assets.manager.get(Constant.ALL_COMPONENTS_PATH + "/skeleton.atlas", TextureAtlas.class);
It turns out to be black rectangle ... with the components