com.badlogic.gdx.graphics.g2d
Class TextureAtlas

java.lang.Object
  extended by com.badlogic.gdx.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.

Author:
Nathan Sweet

Nested Class Summary
static class TextureAtlas.AtlasRegion
          Describes the region of a packed image and provides information about the original image before it was packed.
static class TextureAtlas.AtlasSprite
          A sprite that, if whitespace was stripped from the region when it was packed, is automatically positioned as if whitespace had not been stripped.
static class TextureAtlas.TextureAtlasData
           
 
Constructor Summary
TextureAtlas()
          Creates an empty atlas to which regions can be added.
TextureAtlas(FileHandle packFile)
          Loads the specified pack file, using the parent directory of the pack file to find the page images.
TextureAtlas(FileHandle packFile, boolean flip)
           
TextureAtlas(FileHandle packFile, FileHandle imagesDir)
           
TextureAtlas(FileHandle packFile, FileHandle imagesDir, boolean flip)
           
TextureAtlas(String internalPackFile)
          Loads the specified pack file using Files.FileType.Internal, using the parent directory of the pack file to find the page images.
TextureAtlas(TextureAtlas.TextureAtlasData data)
           
 
Method Summary
 TextureAtlas.AtlasRegion addRegion(String name, Texture texture, int x, int y, int width, int height)
          Adds a region to the atlas.
 TextureAtlas.AtlasRegion addRegion(String name, TextureRegion textureRegion)
          Adds a region to the atlas.
 NinePatch createPatch(String name)
          Returns the first region found with the specified name as a NinePatch.
 Sprite createSprite(String name)
          Returns the first region found with the specified name as a sprite.
 Sprite createSprite(String name, int index)
          Returns the first region found with the specified name and index as a sprite.
 Array<Sprite> createSprites()
          Returns all regions in the atlas as sprites.
 Array<Sprite> createSprites(String name)
          Returns all regions with the specified name as sprites, ordered by smallest to largest index.
 void dispose()
          Releases all resources associated with this TextureAtlas instance.
 TextureAtlas.AtlasRegion findRegion(String name)
          Returns the first region found with the specified name.
 TextureAtlas.AtlasRegion findRegion(String name, int index)
          Returns the first region found with the specified name and index.
 Array<TextureAtlas.AtlasRegion> findRegions(String name)
          Returns all regions with the specified name, ordered by smallest to largest index.
 Array<TextureAtlas.AtlasRegion> getRegions()
          Returns all regions in the atlas.
 Set<Texture> getTextures()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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.FileType.Internal, using the parent directory of the pack file to find the page images.


TextureAtlas

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


TextureAtlas

public TextureAtlas(FileHandle 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(FileHandle)

TextureAtlas

public TextureAtlas(FileHandle packFile,
                    FileHandle imagesDir)

TextureAtlas

public TextureAtlas(FileHandle packFile,
                    FileHandle 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 Detail

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 Array<TextureAtlas.AtlasRegion> getRegions()
Returns all regions in the atlas.


findRegion

public TextureAtlas.AtlasRegion findRegion(String name)
Returns the first region found with the specified name. This method uses string comparison to find the region, so the result should be cached rather than calling this method multiple times.

Returns:
The region, or null.

findRegion

public TextureAtlas.AtlasRegion findRegion(String name,
                                           int index)
Returns the first region found with the specified name and index. This method uses string comparison to find the region, so the result should be cached rather than calling this method multiple times.

Returns:
The region, or null.

findRegions

public Array<TextureAtlas.AtlasRegion> findRegions(String name)
Returns all regions with the specified name, ordered by smallest to largest index. This method uses string comparison to find the regions, so the result should be cached rather than calling this method multiple times.


createSprites

public Array<Sprite> createSprites()
Returns all regions in the atlas as sprites. This method creates a new sprite for each region, so the result should be stored rather than calling this method multiple times.

See Also:
createSprite(String)

createSprite

public Sprite createSprite(String name)
Returns the first region found with the specified name as a sprite. If whitespace was stripped from the region when it was packed, the sprite is automatically positioned as if whitespace had not been stripped. This method uses string comparison to find the region and constructs a new sprite, so the result should be cached rather than calling this method multiple times.

Returns:
The sprite, or null.

createSprite

public Sprite createSprite(String name,
                           int index)
Returns the first region found with the specified name and index as a sprite. This method uses string comparison to find the region and constructs a new sprite, so the result should be cached rather than calling this method multiple times.

Returns:
The sprite, or null.
See Also:
createSprite(String)

createSprites

public Array<Sprite> createSprites(String name)
Returns all regions with the specified name as sprites, ordered by smallest to largest index. This method uses string comparison to find the regions and constructs new sprites, so the result should be cached rather than calling this method multiple times.

See Also:
createSprite(String)

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 Set<Texture> getTextures()
Returns:
the textures of the pages, unordered

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


Copyright © 2013. All Rights Reserved.