Package arc.graphics.g2d
Class TextureAtlas
java.lang.Object
arc.graphics.g2d.TextureAtlas
- All Implemented Interfaces:
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
-
Field Summary
Modifier and TypeFieldDescriptionprotected float
protected TextureAtlas.AtlasRegion
protected TextureAtlas.AtlasRegion
-
Constructor Summary
ConstructorDescriptionCreates an empty atlas to which regions can be added.TextureAtlas
(Fi packFile) Loads the specified pack file, using the parent directory of the pack file to find the page images.TextureAtlas
(Fi packFile, boolean flip) TextureAtlas
(Fi packFile, Fi imagesDir) TextureAtlas
(Fi packFile, Fi imagesDir, boolean flip) TextureAtlas
(String internalPackFile) Loads the specified pack file usingFiles.internal(java.lang.String)
, using the parent directory of the pack file to find the page images. -
Method Summary
Modifier and TypeMethodDescriptionaddRegion
(String name, TextureRegion textureRegion) Adds a region to the atlas.Adds a region to the atlas.static TextureAtlas
Returns a new texture atlas with only a blank texture region.createPatch
(String name) Returns the first region found with the specified name as aNinePatch
.void
dispose()
Releases all resources associated with this TextureAtlas instance.void
disposePixmap
(Texture texture) Always creates a new drawable by name.Returns the first region found with the specified name.find
(String name, TextureRegion def) <T extends Drawable>
TgetDrawable
(String name) getPixmap
(TextureAtlas.AtlasRegion region) getPixmap
(TextureRegion region) Returns the region map in the atlas.Returns all regions in the atlas.boolean
boolean
isFound
(TextureRegion region) void
setDrawableScale
(float scale) boolean
setErrorRegion
(String name) Finds and sets error region as name.texture()
white()
Returns the blank 1x1 texture region, if it exists.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface arc.util.Disposable
isDisposed
-
Field Details
-
error
-
white
-
drawableScale
protected float drawableScale
-
-
Constructor Details
-
TextureAtlas
public TextureAtlas()Creates an empty atlas to which regions can be added. -
TextureAtlas
Loads the specified pack file usingFiles.internal(java.lang.String)
, using the parent directory of the pack file to find the page images. -
TextureAtlas
Loads the specified pack file, using the parent directory of the pack file to find the page images. -
TextureAtlas
- 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
-
TextureAtlas
- Parameters:
flip
- If true, all regions loaded will be flipped for use with a perspective where 0,0 is the upper left corner.
-
TextureAtlas
- Parameters:
data
- May be null.
-
-
Method Details
-
blankAtlas
Returns a new texture atlas with only a blank texture region. -
setDrawableScale
public void setDrawableScale(float scale) -
getPixmap
-
getPixmap
-
getPixmaps
-
disposePixmap
-
getPixmap
-
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
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. -
getRegionMap
Returns the region map in the atlas. -
white
Returns the blank 1x1 texture region, if it exists. -
setErrorRegion
Finds and sets error region as name. -
isFound
-
find
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
-
find
-
has
-
getDrawable
-
drawable
Always creates a new drawable by name. If nothing is found, returns an 'error' texture region drawable. -
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
- Returns:
- the textures of the pages, unordered
-
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 interfaceDisposable
-