Class TextureAtlas
- java.lang.Object
-
- gaia.cu9.ari.gaiaorbit.util.gdx.g2d.TextureAtlas
-
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
public class TextureAtlas extends java.lang.Object implements com.badlogic.gdx.utils.Disposable
Loads images from texture atlases created by TexturePacker.
A TextureAtlas must be disposed to free up the resources consumed by the backing textures.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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
Constructors Constructor Description TextureAtlas()
Creates an empty atlas to which regions can be added.TextureAtlas(com.badlogic.gdx.files.FileHandle packFile)
Loads the specified pack file, using the parent directory of the pack file to find the page images.TextureAtlas(com.badlogic.gdx.files.FileHandle packFile, boolean flip)
TextureAtlas(com.badlogic.gdx.files.FileHandle packFile, com.badlogic.gdx.files.FileHandle imagesDir)
TextureAtlas(com.badlogic.gdx.files.FileHandle packFile, com.badlogic.gdx.files.FileHandle imagesDir, boolean flip)
TextureAtlas(TextureAtlas.TextureAtlasData data)
TextureAtlas(java.lang.String internalPackFile)
Loads the specified pack file usingFiles.FileType.Internal
, using the parent directory of the pack file to find the page images.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TextureAtlas.AtlasRegion
addRegion(java.lang.String name, com.badlogic.gdx.graphics.Texture texture, int x, int y, int width, int height)
Adds a region to the atlas.TextureAtlas.AtlasRegion
addRegion(java.lang.String name, TextureRegion textureRegion)
Adds a region to the atlas.NinePatch
createPatch(java.lang.String name)
Returns the first region found with the specified name as aNinePatch
.Sprite
createSprite(java.lang.String name)
Returns the first region found with the specified name as a sprite.Sprite
createSprite(java.lang.String name, int index)
Returns the first region found with the specified name and index as a sprite.com.badlogic.gdx.utils.Array<Sprite>
createSprites()
Returns all regions in the atlas as sprites.com.badlogic.gdx.utils.Array<Sprite>
createSprites(java.lang.String name)
Returns all regions with the specified name as sprites, ordered by smallest to largestindex
.void
dispose()
Releases all resources associated with this TextureAtlas instance.TextureAtlas.AtlasRegion
findRegion(java.lang.String name)
Returns the first region found with the specified name.TextureAtlas.AtlasRegion
findRegion(java.lang.String name, int index)
Returns the first region found with the specified name and index.com.badlogic.gdx.utils.Array<TextureAtlas.AtlasRegion>
findRegions(java.lang.String name)
Returns all regions with the specified name, ordered by smallest to largestindex
.com.badlogic.gdx.utils.Array<TextureAtlas.AtlasRegion>
getRegions()
Returns all regions in the atlas.com.badlogic.gdx.utils.ObjectSet<com.badlogic.gdx.graphics.Texture>
getTextures()
-
-
-
Constructor Detail
-
TextureAtlas
public TextureAtlas()
Creates an empty atlas to which regions can be added.
-
TextureAtlas
public TextureAtlas(java.lang.String internalPackFile)
Loads the specified pack file usingFiles.FileType.Internal
, using the parent directory of the pack file to find the page images.
-
TextureAtlas
public TextureAtlas(com.badlogic.gdx.files.FileHandle packFile)
Loads the specified pack file, using the parent directory of the pack file to find the page images.
-
TextureAtlas
public TextureAtlas(com.badlogic.gdx.files.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(com.badlogic.gdx.files.FileHandle packFile, com.badlogic.gdx.files.FileHandle imagesDir)
-
TextureAtlas
public TextureAtlas(com.badlogic.gdx.files.FileHandle packFile, com.badlogic.gdx.files.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(java.lang.String name, com.badlogic.gdx.graphics.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(java.lang.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 com.badlogic.gdx.utils.Array<TextureAtlas.AtlasRegion> getRegions()
Returns all regions in the atlas.
-
findRegion
public TextureAtlas.AtlasRegion findRegion(java.lang.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(java.lang.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 com.badlogic.gdx.utils.Array<TextureAtlas.AtlasRegion> findRegions(java.lang.String name)
Returns all regions with the specified name, ordered by smallest to largestindex
. This method uses string comparison to find the regions, so the result should be cached rather than calling this method multiple times.
-
createSprites
public com.badlogic.gdx.utils.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(java.lang.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(java.lang.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 com.badlogic.gdx.utils.Array<Sprite> createSprites(java.lang.String name)
Returns all regions with the specified name as sprites, ordered by smallest to largestindex
. 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(java.lang.String name)
Returns the first region found with the specified name as aNinePatch
. 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 com.badlogic.gdx.utils.ObjectSet<com.badlogic.gdx.graphics.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 interfacecom.badlogic.gdx.utils.Disposable
-
-