Search in sources :

Example 16 with TextureAtlasData

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();
        }
    });
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) FileHandle(com.badlogic.gdx.files.FileHandle) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Page(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)16 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)16 File (java.io.File)12 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)10 JAXBContext (javax.xml.bind.JAXBContext)5 Unmarshaller (javax.xml.bind.Unmarshaller)5 BaseMap (objects.BaseMap)5 MapSet (objects.MapSet)5 Tile (objects.Tile)5 TileSet (objects.TileSet)5 Array (com.badlogic.gdx.utils.Array)4 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)4 FileInputStream (java.io.FileInputStream)3 Texture (com.badlogic.gdx.graphics.Texture)2 Page (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)1 AssetManager (com.badlogic.gdx.assets.AssetManager)1