Package gaiasky.util.gdx.g2d
Class TextureAtlas
java.lang.Object
gaiasky.util.gdx.g2d.TextureAtlas
- All Implemented Interfaces:
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.
A TextureAtlas must be disposed to free up the resources consumed by the backing textures.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Describes the region of a packed image and provides information about the original image before it was packed.static class
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddRegion
(String name, com.badlogic.gdx.graphics.Texture texture, int x, int y, int width, int height) Adds a region to the atlas.addRegion
(String name, TextureRegion textureRegion) Adds a region to the atlas.createPatch
(String name) Returns the first region found with the specified name as aNinePatch
.createSprite
(String name) Returns the first region found with the specified name as a sprite.createSprite
(String name, int index) Returns the first region found with the specified name and index as a sprite.com.badlogic.gdx.utils.Array
<Sprite> Returns all regions in the atlas as sprites.com.badlogic.gdx.utils.Array
<Sprite> createSprites
(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.findRegion
(String name) Returns the first region found with the specified name.findRegion
(String name, int index) Returns the first region found with the specified name and index.com.badlogic.gdx.utils.Array
<TextureAtlas.AtlasRegion> findRegions
(String name) Returns all regions with the specified name, ordered by smallest to largestindex
.com.badlogic.gdx.utils.Array
<TextureAtlas.AtlasRegion> Returns all regions in the atlas.com.badlogic.gdx.utils.ObjectSet
<com.badlogic.gdx.graphics.Texture>
-
Constructor Details
-
TextureAtlas
- Parameters:
data
- May be null.
-
-
Method Details
-
addRegion
public TextureAtlas.AtlasRegion addRegion(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
Adds a region to the atlas. The texture for the specified region will be disposed when the atlas is disposed. -
getRegions
Returns all regions in the atlas. -
findRegion
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
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
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
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
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
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:
-
createSprites
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:
-
createPatch
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
-