Package arc.graphics.g2d
Class TextureRegion
java.lang.Object
arc.graphics.g2d.TextureRegion
- Direct Known Subclasses:
TextureAtlas.AtlasRegion
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.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs a region with no texture and no coordinates defined.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
Modifier and TypeMethodDescriptionasAtlas()
void
flip
(boolean x, boolean y) boolean
found()
int
getX()
int
getY()
boolean
isFlipX()
boolean
isFlipY()
float
ratio()
float
scl()
void
scroll
(float xAmount, float yAmount) Offsets the region relative to the current region.void
set
(float u, float v, float u2, float v2) set
(int x, int y, int width, int height) void
set
(TextureRegion region) Sets the texture and coordinates to the specified region.void
set
(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.void
Sets the texture and sets the coordinates to the size of the specified texture.void
Sets the texture to that of the specified region and sets the coordinates relative to the specified region.void
setHeight
(float height) void
setHeight
(int height) void
setU
(float u) void
setU2
(float u2) void
setV
(float v) void
setV2
(float v2) void
setWidth
(float width) void
setWidth
(int width) void
setX
(float x) void
setX
(int x) void
setY
(float y) void
setY
(int y) TextureRegion[][]
split
(int tileWidth, int tileHeight) Helper function 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[][]
Helper function to create tiles out of the givenTexture
starting from the top left corner going to the right and ending at the bottom right corner.toString()
-
Field Details
-
texture
-
u
public float uRead-only. Use setters to change. -
v
public float vRead-only. Use setters to change. -
u2
public float u2Read-only. Use setters to change. -
v2
public float v2Read-only. Use setters to change. -
width
public int widthRead-only. Use setters to change. -
height
public int heightRead-only. Use setters to change. -
scale
public float scale
-
-
Constructor Details
-
TextureRegion
public TextureRegion()Constructs a region with no texture and no coordinates defined. -
TextureRegion
Constructs a region the size of the specified texture. -
TextureRegion
- 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
- 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
-
TextureRegion
Constructs a region with the same texture and coordinates of the specified region. -
TextureRegion
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 Details
-
split
Helper function to create tiles out of the givenTexture
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
- the TexturetileWidth
- a tile's width in pixelstileHeight
- a tile's height in pixels- Returns:
- a 2D array of TextureRegions indexed by [row][column].
-
asAtlas
-
found
public boolean found() -
set
Sets the texture and sets the coordinates to the size of the specified texture. -
set
- 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.
-
set
public void set(float u, float v, float u2, float v2) -
set
Sets the texture and coordinates to the specified region. -
set
Sets the texture to that of the specified region and sets the coordinates relative to the specified region. -
set
Sets the texture to that of the specified region and sets the coordinates relative to the specified region. -
setU
public void setU(float u) -
setV
public void setV(float v) -
setU2
public void setU2(float u2) -
setV2
public void setV2(float v2) -
getX
public int getX() -
setX
public void setX(int x) -
setX
public void setX(float x) -
getY
public int getY() -
setY
public void setY(int y) -
setY
public void setY(float y) -
setWidth
public void setWidth(int width) -
setHeight
public void setHeight(int height) -
setWidth
public void setWidth(float width) -
setHeight
public void setHeight(float height) -
flip
public void flip(boolean x, boolean y) -
ratio
public float ratio()- Returns:
- x/y aspect ratio
-
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
Helper function 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 form 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].
-
scl
public float scl() -
toString
-