public class Skin extends java.lang.Object implements Disposable
See the documentation for more.
Modifier and Type | Class and Description |
---|---|
static class |
Skin.TintedDrawable |
Constructor and Description |
---|
Skin()
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.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String name,
java.lang.Object resource) |
void |
add(java.lang.String name,
java.lang.Object resource,
java.lang.Class type) |
void |
addRegions(TextureAtlas atlas)
Adds all named texture regions from the atlas.
|
void |
dispose()
Disposes the
TextureAtlas and all Disposable resources in the skin. |
java.lang.String |
find(java.lang.Object resource)
Returns the name of the specified style object, or null if it is not in the skin.
|
<T> T |
get(java.lang.Class<T> type)
Returns a resource named "default" for the specified type.
|
<T> T |
get(java.lang.String name,
java.lang.Class<T> type)
Returns a named resource of the specified type.
|
<T> ObjectMap<java.lang.String,T> |
getAll(java.lang.Class<T> type)
Returns the name to resource mapping for the specified type, or null if no resources of that type exist.
|
TextureAtlas |
getAtlas()
Returns the
TextureAtlas passed to this skin constructor, or null. |
Color |
getColor(java.lang.String name) |
Drawable |
getDrawable(java.lang.String name)
Returns a registered drawable.
|
BitmapFont |
getFont(java.lang.String name) |
ObjectMap<java.lang.String,java.lang.Class> |
getJsonClassTags()
Returns a map of
class tags that will be used when loading skin JSON. |
protected Json |
getJsonLoader(FileHandle skinFile) |
NinePatch |
getPatch(java.lang.String name)
Returns a registered ninepatch.
|
TextureRegion |
getRegion(java.lang.String name)
Returns a registered texture region.
|
Array<TextureRegion> |
getRegions(java.lang.String regionName) |
Sprite |
getSprite(java.lang.String name)
Returns a registered sprite.
|
TiledDrawable |
getTiledDrawable(java.lang.String name)
Returns a registered tiled drawable.
|
boolean |
has(java.lang.String name,
java.lang.Class type) |
void |
load(FileHandle skinFile)
Adds all resources in the specified skin JSON file.
|
Drawable |
newDrawable(Drawable drawable)
Returns a copy of the specified drawable.
|
Drawable |
newDrawable(Drawable drawable,
Color tint)
Returns a tinted copy of a drawable found in the skin via
getDrawable(String) . |
Drawable |
newDrawable(Drawable drawable,
float r,
float g,
float b,
float a)
Returns a tinted copy of a drawable found in the skin via
getDrawable(String) . |
Drawable |
newDrawable(java.lang.String name)
Returns a copy of a drawable found in the skin via
getDrawable(String) . |
Drawable |
newDrawable(java.lang.String name,
Color tint)
Returns a tinted copy of a drawable found in the skin via
getDrawable(String) . |
Drawable |
newDrawable(java.lang.String name,
float r,
float g,
float b,
float a)
Returns a tinted copy of a drawable found in the skin via
getDrawable(String) . |
<T> T |
optional(java.lang.String name,
java.lang.Class<T> type)
Returns a named resource of the specified type.
|
void |
remove(java.lang.String name,
java.lang.Class type) |
void |
scale(Drawable drawble)
Scales the drawable's
Drawable.getLeftWidth() , Drawable.getRightWidth() ,
Drawable.getBottomHeight() , Drawable.getTopHeight() , Drawable.getMinWidth() , and
Drawable.getMinHeight() . |
void |
setEnabled(Actor actor,
boolean enabled)
Sets the style on the actor to disabled or enabled.
|
void |
setScale(float scale)
The scale used to size drawables created by this skin.
|
public Skin()
public Skin(FileHandle skinFile)
TextureAtlas
and the texture regions added to the skin. The atlas is
automatically disposed when the skin is disposed.public Skin(FileHandle skinFile, TextureAtlas atlas)
public Skin(TextureAtlas atlas)
public void load(FileHandle skinFile)
public void addRegions(TextureAtlas atlas)
public void add(java.lang.String name, java.lang.Object resource)
public void add(java.lang.String name, java.lang.Object resource, java.lang.Class type)
public void remove(java.lang.String name, java.lang.Class type)
public <T> T get(java.lang.Class<T> type)
GdxRuntimeException
- if the resource was not found.public <T> T get(java.lang.String name, java.lang.Class<T> type)
GdxRuntimeException
- if the resource was not found.@Null public <T> T optional(java.lang.String name, java.lang.Class<T> type)
public boolean has(java.lang.String name, java.lang.Class type)
@Null public <T> ObjectMap<java.lang.String,T> getAll(java.lang.Class<T> type)
public Color getColor(java.lang.String name)
public BitmapFont getFont(java.lang.String name)
public TextureRegion getRegion(java.lang.String name)
@Null public Array<TextureRegion> getRegions(java.lang.String regionName)
TextureRegion
that have an index != -1, or null if none are found.public TiledDrawable getTiledDrawable(java.lang.String name)
public NinePatch getPatch(java.lang.String name)
TextureAtlas.AtlasRegion
then its split TextureAtlas.AtlasRegion.values
are used,
otherwise the ninepatch will have the region as the center patch.public Sprite getSprite(java.lang.String name)
TextureAtlas.AtlasRegion
then an TextureAtlas.AtlasSprite
is used if the region has been
whitespace stripped or packed rotated 90 degrees.public Drawable getDrawable(java.lang.String name)
@Null public java.lang.String find(java.lang.Object resource)
public Drawable newDrawable(java.lang.String name)
getDrawable(String)
.public Drawable newDrawable(java.lang.String name, float r, float g, float b, float a)
getDrawable(String)
.public Drawable newDrawable(java.lang.String name, Color tint)
getDrawable(String)
.public Drawable newDrawable(Drawable drawable)
public Drawable newDrawable(Drawable drawable, float r, float g, float b, float a)
getDrawable(String)
.public Drawable newDrawable(Drawable drawable, Color tint)
getDrawable(String)
.public void scale(Drawable drawble)
Drawable.getLeftWidth()
, Drawable.getRightWidth()
,
Drawable.getBottomHeight()
, Drawable.getTopHeight()
, Drawable.getMinWidth()
, and
Drawable.getMinHeight()
.public void setScale(float scale)
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.
public void setEnabled(Actor actor, boolean enabled)
@Null public TextureAtlas getAtlas()
TextureAtlas
passed to this skin constructor, or null.public void dispose()
TextureAtlas
and all Disposable
resources in the skin.dispose
in interface Disposable
protected Json getJsonLoader(FileHandle skinFile)
public ObjectMap<java.lang.String,java.lang.Class> getJsonClassTags()
class tags
that will be used when loading skin JSON. The map can
be modified before calling load(FileHandle)
. By default the map is populated with the simple class names of libGDX
classes commonly used in skins.