APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics.g2d

public Class TextureRegion

extends Object
Class Inheritance
Known Direct Subclasses
com.badlogic.gdx.graphics.g2d.Sprite, com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion
Imports
com.badlogic.gdx.graphics.Texture

Defines a rectangular area of a texture. The coordinate system used has its origin in the upper left corner with the x-axis pointing to the right and the y axis pointing downwards.
Authors
mzechner, Nathan Sweet

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int
pack-priv Texture
pack-priv float
u

pack-priv float
pack-priv float
v

pack-priv float

Constructor Summary

AccessConstructor and Description
public
TextureRegion()

Constructs a region that cannot be used until a texture and texture coordinates are set.

public
TextureRegion(Texture texture)

Constructs a region the size of the specified texture.

public
TextureRegion(Texture texture, int
The width of the texture region. May be negative to flip the sprite when drawn.
width
,
int
The height of the texture region. May be negative to flip the sprite when drawn.
height
)

public
TextureRegion(Texture texture, int x, int y, int
The width of the texture region. May be negative to flip the sprite when drawn.
width
,
int
The height of the texture region. May be negative to flip the sprite when drawn.
height
)

public
TextureRegion(Texture texture, float u, float v, float u2, float v2)

public
TextureRegion(TextureRegion region)

Constructs a region with the same texture and coordinates of the specified region.

public
TextureRegion(TextureRegion region, int x, int y, int
The width of the texture region. May be negative to flip the sprite when drawn.
width
,
int
The height of the texture region. May be negative to flip the sprite when drawn.
height
)

Constructs a region with the same texture as the specified region and sets the coordinates relative to the specified region.

Method Summary

Modifier and TypeMethod and Description
public void
flip(boolean x, boolean y)

public int
getRegionHeight()

Returns the region's height.

public int
getRegionWidth()

Returns the region's width.

public int
public int
public Texture
public float
getU()

public float
public float
getV()

public float
public boolean
public boolean
public void
scroll(float
The percentage to offset horizontally.
xAmount
,
float
The percentage to offset vertically. This is done in texture space, so up is negative.
yAmount
)

Offsets the region relative to the current region.

public void
setRegion(Texture texture)

Sets the texture and sets the coordinates to the size of the specified texture.

public void
setRegion(int x, int y, int
The width of the texture region. May be negative to flip the sprite when drawn.
width
,
int
The height of the texture region. May be negative to flip the sprite when drawn.
height
)

public void
setRegion(float u, float v, float u2, float v2)

public void
setRegion(TextureRegion region)

Sets the texture and coordinates to the specified region.

public void
setRegion(TextureRegion region, int x, int y, int width, int height)

Sets the texture to that of the specified region and sets the coordinates relative to the specified region.

public void
setRegionHeight(int height)

public void
setRegionWidth(int width)

public void
setRegionX(int x)

public void
setRegionY(int y)

public void
public void
setU(float u)

public void
setU2(float u2)

public void
setV(float v)

public void
setV2(float v2)

public TextureRegion[][]

Returns:

a 2D array of TextureRegions indexed by [row][column].
split
(int
a tile's width in pixels
tileWidth
,
int
a tile's height in pixels
tileHeight
)

Helper method to create tiles out of this TextureRegion starting from the top left corner going to the right and ending at the bottom right corner.

public static TextureRegion[][]

Returns:

a 2D array of TextureRegions indexed by [row][column].
split
(Texture
the Texture
texture
,
int
a tile's width in pixels
tileWidth
,
int
a tile's height in pixels
tileHeight
)

Helper method to create tiles out of the given Texture starting from the top left corner going to the right and ending at the bottom right corner.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

regionHeightback to summary
pack-priv int regionHeight
regionWidthback to summary
pack-priv int regionWidth
textureback to summary
pack-priv Texture texture
uback to summary
pack-priv float u
u2back to summary
pack-priv float u2
vback to summary
pack-priv float v
v2back to summary
pack-priv float v2

Constructor Detail

TextureRegionback to summary
public TextureRegion()

Constructs a region that cannot be used until a texture and texture coordinates are set.

TextureRegionback to summary
public TextureRegion(Texture texture)

Constructs a region the size of the specified texture.

TextureRegionback to summary
public TextureRegion(Texture texture, int width, int height)
Parameters
width:int

The width of the texture region. May be negative to flip the sprite when drawn.

height:int

The height of the texture region. May be negative to flip the sprite when drawn.

TextureRegionback to summary
public TextureRegion(Texture texture, int x, int y, int width, int height)
Parameters
width:int

The width of the texture region. May be negative to flip the sprite when drawn.

height:int

The height of the texture region. May be negative to flip the sprite when drawn.

TextureRegionback to summary
public TextureRegion(Texture texture, float u, float v, float u2, float v2)
TextureRegionback to summary
public TextureRegion(TextureRegion region)

Constructs a region with the same texture and coordinates of the specified region.

TextureRegionback to summary
public TextureRegion(TextureRegion region, int x, int y, int width, int height)

Constructs a region with the same texture as the specified region and sets the coordinates relative to the specified region.

Parameters
width:int

The width of the texture region. May be negative to flip the sprite when drawn.

height:int

The height of the texture region. May be negative to flip the sprite when drawn.

Method Detail

flipback to summary
public void flip(boolean x, boolean y)
getRegionHeightback to summary
public int getRegionHeight()

Returns the region's height.

getRegionWidthback to summary
public int getRegionWidth()

Returns the region's width.

getRegionXback to summary
public int getRegionX()
getRegionYback to summary
public int getRegionY()
getTextureback to summary
public Texture getTexture()
getUback to summary
public float getU()
getU2back to summary
public float getU2()
getVback to summary
public float getV()
getV2back to summary
public float getV2()
isFlipXback to summary
public boolean isFlipX()
isFlipYback to summary
public boolean isFlipY()
scrollback to summary
public void scroll(float xAmount, float yAmount)

Offsets the region relative to the current region. Generally the region's size should be the entire size of the texture in the direction(s) it is scrolled.

Parameters
xAmount:float

The percentage to offset horizontally.

yAmount:float

The percentage to offset vertically. This is done in texture space, so up is negative.

setRegionback to summary
public void setRegion(Texture texture)

Sets the texture and sets the coordinates to the size of the specified texture.

setRegionback to summary
public void setRegion(int x, int y, int width, int height)
Parameters
width:int

The width of the texture region. May be negative to flip the sprite when drawn.

height:int

The height of the texture region. May be negative to flip the sprite when drawn.

setRegionback to summary
public void setRegion(float u, float v, float u2, float v2)
setRegionback to summary
public void setRegion(TextureRegion region)

Sets the texture and coordinates to the specified region.

setRegionback to summary
public void setRegion(TextureRegion region, int x, int y, int width, int height)

Sets the texture to that of the specified region and sets the coordinates relative to the specified region.

setRegionHeightback to summary
public void setRegionHeight(int height)
setRegionWidthback to summary
public void setRegionWidth(int width)
setRegionXback to summary
public void setRegionX(int x)
setRegionYback to summary
public void setRegionY(int y)
setTextureback to summary
public void setTexture(Texture texture)
setUback to summary
public void setU(float u)
setU2back to summary
public void setU2(float u2)
setVback to summary
public void setV(float v)
setV2back to summary
public void setV2(float v2)
splitback to summary
public TextureRegion[][] split(int tileWidth, int tileHeight)

Helper method to create tiles out of this TextureRegion starting from the top left corner going to the right and ending at the bottom right corner. Only complete tiles will be returned so if the region's width or height are not a multiple of the tile width and height not all of the region will be used. This will not work on texture regions returned from a TextureAtlas that either have whitespace removed or where flipped before the region is split.

Parameters
tileWidth:int

a tile's width in pixels

tileHeight:int

a tile's height in pixels

Returns:TextureRegion[][]

a 2D array of TextureRegions indexed by [row][column].

splitback to summary
public static TextureRegion[][] split(Texture texture, int tileWidth, int tileHeight)

Helper method to create tiles out of the given Texture starting from the top left corner going to the right and ending at the bottom right corner. Only complete tiles will be returned so if the texture's width or height are not a multiple of the tile width and height not all of the texture will be used.

Parameters
texture:Texture

the Texture

tileWidth:int

a tile's width in pixels

tileHeight:int

a tile's height in pixels

Returns:TextureRegion[][]

a 2D array of TextureRegions indexed by [row][column].