Class TextureRegion

java.lang.Object
arc.graphics.g2d.TextureRegion
Direct Known Subclasses:
TextureAtlas.AtlasRegion

public class TextureRegion extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    int
    Read-only.
    float
     
     
    float
    Read-only.
    float
    Read-only.
    float
    Read-only.
    float
    Read-only.
    int
    Read-only.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a region with no texture and no coordinates defined.
    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.
    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 Type
    Method
    Description
     
    void
    flip(boolean x, boolean y)
     
    boolean
     
    int
     
    int
     
    boolean
     
    boolean
     
    float
     
    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
    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
    set(Texture texture)
    Sets the texture and sets the coordinates to the size of the specified texture.
    void
    set(Texture texture, 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
    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)
     
    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[][]
    split(Texture texture, int tileWidth, int tileHeight)
    Helper function 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.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • texture

      public Texture texture
    • u

      public float u
      Read-only. Use setters to change.
    • v

      public float v
      Read-only. Use setters to change.
    • u2

      public float u2
      Read-only. Use setters to change.
    • v2

      public float v2
      Read-only. Use setters to change.
    • width

      public int width
      Read-only. Use setters to change.
    • height

      public int height
      Read-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

      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 Details

    • split

      public static TextureRegion[][] split(Texture texture, int tileWidth, int tileHeight)
      Helper function 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 - the Texture
      tileWidth - a tile's width in pixels
      tileHeight - a tile's height in pixels
      Returns:
      a 2D array of TextureRegions indexed by [row][column].
    • asAtlas

      public TextureAtlas.AtlasRegion asAtlas()
    • found

      public boolean found()
    • set

      public void set(Texture texture)
      Sets the texture and sets the coordinates to the size of the specified texture.
    • set

      public TextureRegion set(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.
    • set

      public void set(float u, float v, float u2, float v2)
    • set

      public void set(TextureRegion region)
      Sets the texture and coordinates to the specified region.
    • set

      public 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.
    • set

      public void set(Texture texture, 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.
    • 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

      public 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. 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 pixels
      tileHeight - a tile's height in pixels
      Returns:
      a 2D array of TextureRegions indexed by [row][column].
    • scl

      public float scl()
    • toString

      public String toString()
      Overrides:
      toString in class Object