Class TextureAtlas

java.lang.Object
arc.graphics.g2d.TextureAtlas
All Implemented Interfaces:
Disposable

public class TextureAtlas extends Object implements Disposable
Loads images from texture atlases created by TexturePacker.

A TextureAtlas must be disposed to free up the resources consumed by the backing textures.
  • Field Details

  • Constructor Details

    • TextureAtlas

      public TextureAtlas()
      Creates an empty atlas to which regions can be added.
    • TextureAtlas

      public TextureAtlas(String internalPackFile)
      Loads the specified pack file using Files.internal(java.lang.String), using the parent directory of the pack file to find the page images.
    • TextureAtlas

      public TextureAtlas(Fi packFile)
      Loads the specified pack file, using the parent directory of the pack file to find the page images.
    • TextureAtlas

      public TextureAtlas(Fi packFile, boolean flip)
      Parameters:
      flip - If true, all regions loaded will be flipped for use with a perspective where 0,0 is the upper left corner.
      See Also:
    • TextureAtlas

      public TextureAtlas(Fi packFile, Fi imagesDir)
    • TextureAtlas

      public TextureAtlas(Fi packFile, Fi imagesDir, boolean flip)
      Parameters:
      flip - If true, all regions loaded will be flipped for use with a perspective where 0,0 is the upper left corner.
    • TextureAtlas

      public TextureAtlas(TextureAtlas.TextureAtlasData data)
      Parameters:
      data - May be null.
  • Method Details

    • blankAtlas

      public static TextureAtlas blankAtlas()
      Returns a new texture atlas with only a blank texture region.
    • setDrawableScale

      public void setDrawableScale(float scale)
    • getPixmap

      public PixmapRegion getPixmap(String name)
    • getPixmap

      public PixmapRegion getPixmap(TextureAtlas.AtlasRegion region)
    • getPixmaps

      public ObjectMap<Texture,Pixmap> getPixmaps()
    • disposePixmap

      public void disposePixmap(Texture texture)
    • getPixmap

      public PixmapRegion getPixmap(TextureRegion region)
    • addRegion

      public TextureAtlas.AtlasRegion addRegion(String name, Texture texture, int x, int y, int width, int height)
      Adds a region to the atlas. The specified texture will be disposed when the atlas is disposed.
    • addRegion

      public TextureAtlas.AtlasRegion addRegion(String name, TextureRegion textureRegion)
      Adds a region to the atlas. The texture for the specified region will be disposed when the atlas is disposed.
    • getRegions

      public Seq<TextureAtlas.AtlasRegion> getRegions()
      Returns all regions in the atlas.
    • getRegionMap

      public ObjectMap<String,TextureAtlas.AtlasRegion> getRegionMap()
      Returns the region map in the atlas.
    • white

      public TextureAtlas.AtlasRegion white()
      Returns the blank 1x1 texture region, if it exists.
    • setErrorRegion

      public boolean setErrorRegion(String name)
      Finds and sets error region as name.
    • isFound

      public boolean isFound(TextureRegion region)
    • find

      public TextureAtlas.AtlasRegion find(String name)
      Returns the first region found with the specified name. This method's performance is no longer garbage.
      Returns:
      The region, or the error region (if it is defined), or null.
    • find

      public TextureRegion find(String name, String def)
    • find

      public TextureRegion find(String name, TextureRegion def)
    • has

      public boolean has(String s)
    • getDrawable

      public <T extends Drawable> T getDrawable(String name)
    • drawable

      public Drawable drawable(String name)
      Always creates a new drawable by name. If nothing is found, returns an 'error' texture region drawable.
    • createPatch

      public NinePatch createPatch(String name)
      Returns the first region found with the specified name as a NinePatch. The region must have been packed with ninepatch splits. This method uses string comparison to find the region and constructs a new ninepatch, so the result should be cached rather than calling this method multiple times.
      Returns:
      The ninepatch, or null.
    • getTextures

      public ObjectSet<Texture> getTextures()
      Returns:
      the textures of the pages, unordered
    • texture

      public Texture texture()
      Returns:
      the first texture of the pages.
    • dispose

      public void dispose()
      Releases all resources associated with this TextureAtlas instance. This releases all the textures backing all TextureRegions and Sprites, which should no longer be used after calling dispose.
      Specified by:
      dispose in interface Disposable