Class TextureRegion

java.lang.Object
gaiasky.util.gdx.g2d.TextureRegion
Direct Known Subclasses:
Sprite, 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.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a region with no texture and no coordinates defined.
    TextureRegion(com.badlogic.gdx.graphics.Texture texture)
    Constructs a region the size of the specified texture.
    TextureRegion(com.badlogic.gdx.graphics.Texture texture, float u, float v, float u2, float v2)
     
    TextureRegion(com.badlogic.gdx.graphics.Texture texture, int width, int height)
     
    TextureRegion(com.badlogic.gdx.graphics.Texture texture, int x, int y, int width, int height)
     
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    flip(boolean x, boolean y)
     
    int
    Returns the region's height.
    int
    Returns the region's width.
    int
     
    int
     
    com.badlogic.gdx.graphics.Texture
     
    float
     
    float
     
    float
     
    float
     
    boolean
     
    boolean
     
    void
    scroll(float xAmount, float yAmount)
    Offsets the region relative to the current region.
    void
    setRegion(float u, float v, float u2, float v2)
     
    void
    setRegion(int x, int y, int width, int height)
     
    void
    setRegion(com.badlogic.gdx.graphics.Texture texture)
    Sets the texture and sets the coordinates to the size of the specified texture.
    void
    Sets the texture and coordinates to the specified region.
    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.
    void
    setRegionHeight(int height)
     
    void
    setRegionWidth(int width)
     
    void
    setRegionX(int x)
     
    void
    setRegionY(int y)
     
    void
    setTexture(com.badlogic.gdx.graphics.Texture texture)
     
    void
    setU(float u)
     
    void
    setU2(float u2)
     
    void
    setV(float v)
     
    void
    setV2(float v2)
     
    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(com.badlogic.gdx.graphics.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, toString, wait, wait, wait
  • Constructor Details

    • TextureRegion

      public TextureRegion()
      Constructs a region with no texture and no coordinates defined.
    • TextureRegion

      public TextureRegion(com.badlogic.gdx.graphics.Texture texture)
      Constructs a region the size of the specified texture.
    • TextureRegion

      public TextureRegion(com.badlogic.gdx.graphics.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(com.badlogic.gdx.graphics.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(com.badlogic.gdx.graphics.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(com.badlogic.gdx.graphics.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].
    • setRegion

      public void setRegion(com.badlogic.gdx.graphics.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 com.badlogic.gdx.graphics.Texture getTexture()
    • setTexture

      public void setTexture(com.badlogic.gdx.graphics.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 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].