Package com.badlogic.gdx.graphics.g2d
Class TextureRegion
- java.lang.Object
-
- com.badlogic.gdx.graphics.g2d.TextureRegion
-
- Direct Known Subclasses:
Sprite,TextureAtlas.AtlasRegion
public class TextureRegion extends java.lang.ObjectDefines 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.
-
-
Constructor Summary
Constructors Constructor Description TextureRegion()Constructs a region that cannot be used until a texture and texture coordinates are set.TextureRegion(TextureRegion region)Constructs a region with the same texture and coordinates of the specified region.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.TextureRegion(Texture texture)Constructs a region the size of the specified texture.TextureRegion(Texture texture, float u, float v, float u2, float v2)TextureRegion(Texture texture, int width, int height)TextureRegion(Texture texture, int x, int y, int width, int height)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidflip(boolean x, boolean y)intgetRegionHeight()Returns the region's height.intgetRegionWidth()Returns the region's width.intgetRegionX()intgetRegionY()TexturegetTexture()floatgetU()floatgetU2()floatgetV()floatgetV2()booleanisFlipX()booleanisFlipY()voidscroll(float xAmount, float yAmount)Offsets the region relative to the current region.voidsetRegion(float u, float v, float u2, float v2)voidsetRegion(int x, int y, int width, int height)voidsetRegion(TextureRegion region)Sets the texture and coordinates to the specified region.voidsetRegion(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.voidsetRegion(Texture texture)Sets the texture and sets the coordinates to the size of the specified texture.voidsetRegionHeight(int height)voidsetRegionWidth(int width)voidsetRegionX(int x)voidsetRegionY(int y)voidsetTexture(Texture texture)voidsetU(float u)voidsetU2(float u2)voidsetV(float v)voidsetV2(float v2)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.static TextureRegion[][]split(Texture texture, int tileWidth, int tileHeight)Helper method to create tiles out of the givenTexturestarting from the top left corner going to the right and ending at the bottom right corner.
-
-
-
Constructor Detail
-
TextureRegion
public TextureRegion()
Constructs a region that cannot be used until a texture and texture coordinates are set.
-
TextureRegion
public TextureRegion(Texture texture)
Constructs a region the size of the specified texture.
-
TextureRegion
public TextureRegion(Texture texture, int width, int height)
- Parameters:
width- The width of the texture region. May be negative to flip the sprite when drawn.height- The height of the texture region. May be negative to flip the sprite when drawn.
-
TextureRegion
public TextureRegion(Texture texture, int x, int y, int width, int height)
- Parameters:
width- The width of the texture region. May be negative to flip the sprite when drawn.height- The height of the texture region. May be negative to flip the sprite when drawn.
-
TextureRegion
public TextureRegion(Texture texture, float u, float v, float u2, float v2)
-
TextureRegion
public TextureRegion(TextureRegion region)
Constructs a region with the same texture and coordinates of the specified region.
-
TextureRegion
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- The width of the texture region. May be negative to flip the sprite when drawn.height- The height of the texture region. May be negative to flip the sprite when drawn.
-
-
Method Detail
-
setRegion
public void setRegion(Texture texture)
Sets the texture and sets the coordinates to the size of the specified texture.
-
setRegion
public void setRegion(int x, int y, int width, int height)- Parameters:
width- The width of the texture region. May be negative to flip the sprite when drawn.height- The height of the texture region. May be negative to flip the sprite when drawn.
-
setRegion
public void setRegion(float u, float v, float u2, float v2)
-
setRegion
public void setRegion(TextureRegion region)
Sets the texture and coordinates to the specified region.
-
setRegion
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.
-
getTexture
public Texture getTexture()
-
setTexture
public void setTexture(Texture texture)
-
getU
public float getU()
-
setU
public void setU(float u)
-
getV
public float getV()
-
setV
public void setV(float v)
-
getU2
public float getU2()
-
setU2
public void setU2(float u2)
-
getV2
public float getV2()
-
setV2
public void setV2(float v2)
-
getRegionX
public int getRegionX()
-
setRegionX
public void setRegionX(int x)
-
getRegionY
public int getRegionY()
-
setRegionY
public void setRegionY(int y)
-
getRegionWidth
public int getRegionWidth()
Returns the region's width.
-
setRegionWidth
public void setRegionWidth(int width)
-
getRegionHeight
public int getRegionHeight()
Returns the region's height.
-
setRegionHeight
public void setRegionHeight(int height)
-
flip
public void flip(boolean x, boolean y)
-
isFlipX
public boolean isFlipX()
-
isFlipY
public boolean isFlipY()
-
scroll
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- The percentage to offset horizontally.yAmount- The percentage to offset vertically. This is done in texture space, so up is negative.
-
split
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- a tile's width in pixelstileHeight- a tile's height in pixels- Returns:
- a 2D array of TextureRegions indexed by [row][column].
-
split
public static TextureRegion[][] split(Texture texture, int tileWidth, int tileHeight)
Helper method to create tiles out of the givenTexturestarting 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- the TexturetileWidth- a tile's width in pixelstileHeight- a tile's height in pixels- Returns:
- a 2D array of TextureRegions indexed by [row][column].
-
-