use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project commons-gdx by gemserk.
the class LibgdxResourceBuilder method splitLoadingTextureAtlas.
public void splitLoadingTextureAtlas(final String id, final String file) {
FileHandle packFile = Gdx.files.internal(file);
final TextureAtlasData textureAtlasData = new TextureAtlasData(packFile, packFile.parent(), false);
Array<Page> pages = textureAtlasData.getPages();
final String pageTextureSuffix = "_generated_page_";
for (int i = 0; i < pages.size; i++) {
Page page = pages.get(i);
FileHandle textureFile = page.textureFile;
resource(id + pageTextureSuffix + i, texture2(textureFile).format(page.format).useMipMaps(page.useMipMaps).magFilter(page.magFilter).minFilter(page.minFilter));
}
resourceManager.add(id, new DataLoader<TextureAtlas>() {
@Override
public TextureAtlas load() {
Array<Page> pages = textureAtlasData.getPages();
for (int i = 0; i < pages.size; i++) {
Page page = pages.get(i);
try {
String textureResourceId = id + pageTextureSuffix + i;
page.texture = resourceManager.getResourceValue(textureResourceId);
if (page.texture == null)
throw new RuntimeException("The resource " + textureResourceId + " was not found");
} catch (Exception e) {
throw new RuntimeException("Error while loading page for textureAtlas " + id + " - page: " + page.textureFile.path(), e);
}
}
return new TextureAtlas(textureAtlasData);
}
@Override
public void unload(TextureAtlas atlas) {
atlas.dispose();
}
});
}
Aggregations