zhaoweihao

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
У вас нет необходимых прав для просмотра вложений в этом сообщении.
zhaoweihao
  • Сообщения: 3

Nate

BTW, this is a libgdx question, not specifically related to Spine. I'm not familiar with using libgdx with Android fragments, but I'd guess the fragment has a different OpenGL context. You aren't able to use a texture in a different OpenGL context. The texture has a "name" (an int) which only means something in the context where it was loaded. When you use the unknown name in a different context, you just get a black because it doesn't have a texture for that name.
Аватара пользователя
Nate

Nate
  • Сообщения: 9200

zhaoweihao

Thanks!So do you have any ideas on how to loads one time all the images in atlas and use it in every fragment extends to AndroidFragmentApplication?I have no idea how to do this... Because everytime I start a fragment all the resources need to be reload , Thats waste too much time...
zhaoweihao
  • Сообщения: 3

Nate

Sorry, I'm not familiar with Android fragments, nor even the libgdx Android backend. Maybe there is something useful here:
https://stackoverflow.com/questions/24886561/android-opengl-es-2-how-to-use-an-opengl-activity-as-a-fragment-in-the-main-act
Аватара пользователя
Nate

Nate
  • Сообщения: 9200

zhaoweihao

Thanks... need to go to libgdx forum for some help,If you have any helpful solutions please let me know
zhaoweihao
  • Сообщения: 3

badlogic

If you spawn new fragments, a new OpenGL context must be created. The old context, and with it all resources like buffers and textures, will get removed and need to be recreated. There is no way around this, as Android doesn't support context sharing last I checked.
Аватара пользователя
badlogic

Mario
  • Сообщения: 2013


Вернуться в Runtimes