Class Skin
java.lang.Object
com.badlogic.gdx.scenes.scene2d.ui.Skin
- All Implemented Interfaces:
Disposable
A skin stores resources for UI widgets to use (texture regions, ninepatches, fonts, colors, etc). Resources are named and can
be looked up by name and type. Resources can be described in JSON. Skin provides useful conversions, such as allowing access to
regions in the atlas as ninepatches, sprites, drawables, etc. The get* methods return an instance of the object in the skin.
The new* methods return a copy of an instance in the skin.
See the documentation for more.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionSkin()
Creates an empty skin.Skin
(FileHandle skinFile) Creates a skin containing the resources in the specified skin JSON file.Skin
(FileHandle skinFile, TextureAtlas atlas) Creates a skin containing the resources in the specified skin JSON file and the texture regions from the specified atlas.Skin
(TextureAtlas atlas) Creates a skin containing the texture regions from the specified atlas. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
addRegions
(TextureAtlas atlas) Adds all named texture regions from the atlas.void
dispose()
Disposes theTextureAtlas
and allDisposable
resources in the skin.Returns the name of the specified style object, or null if it is not in the skin.<T> T
Returns a resource named "default" for the specified type.<T> T
Returns a named resource of the specified type.Returns the name to resource mapping for the specified type, or null if no resources of that type exist.getAtlas()
Returns theTextureAtlas
passed to this skin constructor, or null.getDrawable
(String name) Returns a registered drawable.Returns a map ofclass tags
that will be used when loading skin JSON.protected Json
getJsonLoader
(FileHandle skinFile) Returns a registered ninepatch.Returns a registered texture region.getRegions
(String regionName) Returns a registered sprite.getTiledDrawable
(String name) Returns a registered tiled drawable.boolean
void
load
(FileHandle skinFile) Adds all resources in the specified skin JSON file.newDrawable
(Drawable drawable) Returns a copy of the specified drawable.newDrawable
(Drawable drawable, float r, float g, float b, float a) Returns a tinted copy of a drawable found in the skin viagetDrawable(String)
.newDrawable
(Drawable drawable, Color tint) Returns a tinted copy of a drawable found in the skin viagetDrawable(String)
.newDrawable
(String name) Returns a copy of a drawable found in the skin viagetDrawable(String)
.newDrawable
(String name, float r, float g, float b, float a) Returns a tinted copy of a drawable found in the skin viagetDrawable(String)
.newDrawable
(String name, Color tint) Returns a tinted copy of a drawable found in the skin viagetDrawable(String)
.<T> T
Returns a named resource of the specified type.void
void
Scales the drawable'sDrawable.getLeftWidth()
,Drawable.getRightWidth()
,Drawable.getBottomHeight()
,Drawable.getTopHeight()
,Drawable.getMinWidth()
, andDrawable.getMinHeight()
.<V> void
setEnabled
(Styleable<V> styleable, boolean enabled) Sets the style on the actor to disabled or enabled.void
setEnabledReflection
(Actor actor, boolean enabled) Deprecated.void
setScale
(float scale) The scale used to size drawables created by this skin.
-
Constructor Details
-
Skin
public Skin()Creates an empty skin. -
Skin
Creates a skin containing the resources in the specified skin JSON file. If a file in the same directory with a ".atlas" extension exists, it is loaded as aTextureAtlas
and the texture regions added to the skin. The atlas is automatically disposed when the skin is disposed. -
Skin
Creates a skin containing the resources in the specified skin JSON file and the texture regions from the specified atlas. The atlas is automatically disposed when the skin is disposed. -
Skin
Creates a skin containing the texture regions from the specified atlas. The atlas is automatically disposed when the skin is disposed.
-
-
Method Details
-
load
Adds all resources in the specified skin JSON file. -
addRegions
Adds all named texture regions from the atlas. The atlas will not be automatically disposed when the skin is disposed. -
add
-
add
-
remove
-
get
Returns a resource named "default" for the specified type.- Throws:
GdxRuntimeException
- if the resource was not found.
-
get
Returns a named resource of the specified type.- Throws:
GdxRuntimeException
- if the resource was not found.
-
optional
Returns a named resource of the specified type.- Returns:
- null if not found.
-
has
-
getAll
Returns the name to resource mapping for the specified type, or null if no resources of that type exist. -
getColor
-
getFont
-
getRegion
Returns a registered texture region. If no region is found but a texture exists with the name, a region is created from the texture and stored in the skin. -
getRegions
- Returns:
- an array with the
TextureRegion
that have an index != -1, or null if none are found.
-
getTiledDrawable
Returns a registered tiled drawable. If no tiled drawable is found but a region exists with the name, a tiled drawable is created from the region and stored in the skin. -
getPatch
Returns a registered ninepatch. If no ninepatch is found but a region exists with the name, a ninepatch is created from the region and stored in the skin. If the region is anTextureAtlas.AtlasRegion
then its splitTextureAtlas.AtlasRegion.values
are used, otherwise the ninepatch will have the region as the center patch. -
getSprite
Returns a registered sprite. If no sprite is found but a region exists with the name, a sprite is created from the region and stored in the skin. If the region is anTextureAtlas.AtlasRegion
then anTextureAtlas.AtlasSprite
is used if the region has been whitespace stripped or packed rotated 90 degrees. -
getDrawable
Returns a registered drawable. If no drawable is found but a region, ninepatch, or sprite exists with the name, then the appropriate drawable is created and stored in the skin. -
find
Returns the name of the specified style object, or null if it is not in the skin. This compares potentially every style object in the skin of the same type as the specified style, which may be a somewhat expensive operation. -
newDrawable
Returns a copy of a drawable found in the skin viagetDrawable(String)
. -
newDrawable
Returns a tinted copy of a drawable found in the skin viagetDrawable(String)
. -
newDrawable
Returns a tinted copy of a drawable found in the skin viagetDrawable(String)
. -
newDrawable
Returns a copy of the specified drawable. -
newDrawable
Returns a tinted copy of a drawable found in the skin viagetDrawable(String)
. -
newDrawable
Returns a tinted copy of a drawable found in the skin viagetDrawable(String)
. -
scale
Scales the drawable'sDrawable.getLeftWidth()
,Drawable.getRightWidth()
,Drawable.getBottomHeight()
,Drawable.getTopHeight()
,Drawable.getMinWidth()
, andDrawable.getMinHeight()
. -
setScale
public void setScale(float scale) The scale used to size drawables created by this skin.This can be useful when scaling an entire UI (eg with a stage's viewport) then using an atlas with images whose resolution matches the UI scale. The skin can then be scaled the opposite amount so that the larger or smaller images are drawn at the original size. For example, if the UI is scaled 2x, the atlas would have images that are twice the size, then the skin's scale would be set to 0.5.
-
setEnabled
Sets the style on the actor to disabled or enabled. This is done by appending "-disabled" to the style name when enabled is false, and removing "-disabled" from the style name when enabled is true. If the style was not found in the skin, an exception is thrown. -
setEnabledReflection
Deprecated.Sets the style on the actor to disabled or enabled. This is done by appending "-disabled" to the style name when enabled is false, and removing "-disabled" from the style name when enabled is true. A method named "getStyle" is called the actor via reflection and the name of that style is found in the skin. If the actor doesn't have a "getStyle" and "setStyle" method the actor is left unchanged. If the style was not found in the skin, an exception is thrown. -
getAtlas
Returns theTextureAtlas
passed to this skin constructor, or null. -
dispose
public void dispose()Disposes theTextureAtlas
and allDisposable
resources in the skin.- Specified by:
dispose
in interfaceDisposable
-
getJsonLoader
-
getJsonClassTags
Returns a map ofclass tags
that will be used when loading skin JSON. The map can be modified before callingload(FileHandle)
. By default the map is populated with the simple class names of libGDX classes commonly used in skins.
-