* See the License for the specific language governing permissions and\r
* limitations under the License.\r
******************************************************************************/\r
+\r
package com.badlogic.gdx.graphics.g2d;\r
\r
import com.badlogic.gdx.graphics.Texture;\r
\r
-/**\r
- * Defines a rectangular area of a texture. The coordinate system used has its origin in the upper left corner with the x-axis\r
+/** Defines a rectangular area of a texture. The coordinate system used has its origin in the upper left corner with the x-axis\r
* pointing to the right and the y axis pointing downwards.\r
* @author mzechner\r
- * @author Nathan Sweet\r
- */\r
+ * @author Nathan Sweet */\r
public class TextureRegion {\r
Texture texture;\r
float u, v;\r
float u2, v2;\r
\r
- /**\r
- * Constructs a region with no texture and no coordinates defined.\r
- */\r
+ /** Constructs a region with no texture and no coordinates defined. */\r
public TextureRegion () {\r
}\r
\r
- /**\r
- * Constructs a region the size of the specified texture.\r
- */\r
+ /** Constructs a region the size of the specified texture. */\r
public TextureRegion (Texture texture) {\r
this.texture = texture;\r
setRegion(0, 0, texture.getWidth(), texture.getHeight());\r
}\r
\r
- /**\r
- * @param width The width of the texture region. May be negative to flip the sprite when drawn.\r
- * @param height The height of the texture region. May be negative to flip the sprite when drawn.\r
- */\r
+ /** @param width The width of the texture region. May be negative to flip the sprite when drawn.\r
+ * @param height The height of the texture region. May be negative to flip the sprite when drawn. */\r
public TextureRegion (Texture texture, int x, int y, int width, int height) {\r
this.texture = texture;\r
setRegion(x, y, width, height);\r
setRegion(u, v, u2, v2);\r
}\r
\r
- /**\r
- * Constructs a region with the same texture and coordinates of the specified region.\r
- */\r
+ /** Constructs a region with the same texture and coordinates of the specified region. */\r
public TextureRegion (TextureRegion region) {\r
setRegion(region);\r
}\r
\r
- /**\r
- * Constructs a region with the same texture as the specified region and sets the coordinates relative to the specified region.\r
+ /** Constructs a region with the same texture as the specified region and sets the coordinates relative to the specified region.\r
* @param width The width of the texture region. May be negative to flip the sprite when drawn.\r
- * @param height The height of the texture region. May be negative to flip the sprite when drawn.\r
- */\r
+ * @param height The height of the texture region. May be negative to flip the sprite when drawn. */\r
public TextureRegion (TextureRegion region, int x, int y, int width, int height) {\r
setRegion(region, x, y, width, height);\r
}\r
\r
- /**\r
- * Sets the texture and sets the coordinates to the size of the specified texture.\r
- */\r
+ /** Sets the texture and sets the coordinates to the size of the specified texture. */\r
public void setRegion (Texture texture) {\r
this.texture = texture;\r
setRegion(0, 0, texture.getWidth(), texture.getHeight());\r
}\r
\r
- /**\r
- * @param width The width of the texture region. May be negative to flip the sprite when drawn.\r
- * @param height The height of the texture region. May be negative to flip the sprite when drawn.\r
- */\r
+ /** @param width The width of the texture region. May be negative to flip the sprite when drawn.\r
+ * @param height The height of the texture region. May be negative to flip the sprite when drawn. */\r
public void setRegion (int x, int y, int width, int height) {\r
float invTexWidth = 1f / texture.getWidth();\r
float invTexHeight = 1f / texture.getHeight();\r
this.v2 = v2;\r
}\r
\r
- /**\r
- * Sets the texture and coordinates to the specified region.\r
- */\r
+ /** Sets the texture and coordinates to the specified region. */\r
public void setRegion (TextureRegion region) {\r
texture = region.texture;\r
setRegion(region.u, region.v, region.u2, region.v2);\r
}\r
\r
- /**\r
- * Sets the texture to that of the specified region and sets the coordinates relative to the specified region.\r
- */\r
+ /** Sets the texture to that of the specified region and sets the coordinates relative to the specified region. */\r
public void setRegion (TextureRegion region, int x, int y, int width, int height) {\r
texture = region.texture;\r
setRegion(region.getRegionX() + x, region.getRegionY() + y, width, height);\r
setV(y / (float)texture.getHeight());\r
}\r
\r
- /**\r
- * Returns the region's width. May be negative if the texture region is flipped horizontally.\r
- */\r
+ /** Returns the region's width. May be negative if the texture region is flipped horizontally. */\r
public int getRegionWidth () {\r
return (int)((u2 - u) * texture.getWidth());\r
}\r
setU2(u + width / (float)texture.getWidth());\r
}\r
\r
- /**\r
- * Returns the region's height. May be negative if the texture region is flipped horizontally.\r
- */\r
+ /** Returns the region's height. May be negative if the texture region is flipped horizontally. */\r
public int getRegionHeight () {\r
return (int)((v2 - v) * texture.getHeight());\r
}\r
float temp = v;\r
v = v2;\r
v2 = temp;\r
- } \r
+ }\r
}\r
\r
- /**\r
- * Offsets the region relative to the current region. Generally the region's size should be the entire size of the texture in\r
+ /** Offsets the region relative to the current region. Generally the region's size should be the entire size of the texture in\r
* the direction(s) it is scrolled.\r
* @param xAmount The percentage to offset horizontally.\r
- * @param yAmount The percentage to offset vertically. This is done in texture space, so up is negative.\r
- */\r
+ * @param yAmount The percentage to offset vertically. This is done in texture space, so up is negative. */\r
public void scroll (float xAmount, float yAmount) {\r
if (xAmount != 0) {\r
float width = (u2 - u) * texture.getWidth();\r
v2 = v + height / texture.getHeight();\r
}\r
}\r
- \r
- /**\r
- * Helper function to create tiles out of this TextureRegion\r
- * starting from the top left corner going to the left and\r
- * ending at the bottom right corner. Only complete tiles will\r
- * be returned so if the region's width or height are not a \r
- * multiple of the tile width and height not all of the\r
- * region will be used.\r
+\r
+ /** Helper function to create tiles out of this TextureRegion starting from the top left corner going to the left and ending at\r
+ * the bottom right corner. Only complete tiles will be returned so if the region's width or height are not a multiple of the\r
+ * tile width and height not all of the region will be used.\r
* \r
* @param tileWidth a tile's width in pixels\r
* @param tileHeight a tile's height in pixels\r
- * @return a 2D array of TextureRegions indexed by [row][column].\r
- */\r
- public TextureRegion[][] split(int tileWidth, int tileHeight) {\r
+ * @return a 2D array of TextureRegions indexed by [row][column]. */\r
+ public TextureRegion[][] split (int tileWidth, int tileHeight) {\r
int x = getRegionX();\r
int y = getRegionY();\r
int width = getRegionWidth();\r
int height = getRegionHeight();\r
- \r
- if(width < 0) {\r
+\r
+ if (width < 0) {\r
x = x - width;\r
width = -width;\r
}\r
- \r
- if(height < 0) {\r
+\r
+ if (height < 0) {\r
y = y - height;\r
height = -height;\r
}\r
- \r
+\r
int rows = height / tileHeight;\r
- int cols = width / tileWidth; \r
- \r
+ int cols = width / tileWidth;\r
+\r
int startX = x;\r
- TextureRegion[][] tiles = new TextureRegion[rows][cols]; \r
- for(int row = 0; row < rows; row++, y += tileHeight) {\r
+ TextureRegion[][] tiles = new TextureRegion[rows][cols];\r
+ for (int row = 0; row < rows; row++, y += tileHeight) {\r
x = startX;\r
- for(int col = 0; col < cols; col++, x += tileWidth) {\r
+ for (int col = 0; col < cols; col++, x += tileWidth) {\r
tiles[row][col] = new TextureRegion(texture, x, y, tileWidth, tileHeight);\r
}\r
}\r
- \r
+\r
return tiles;\r
}\r
- \r
- /**\r
- * Helper function to create tiles out of the given {@link Texture}\r
- * starting from the top left corner going to the left and\r
- * ending at the bottom right corner. Only complete tiles will\r
- * be returned so if the texture's width or height are not a \r
- * multiple of the tile width and height not all of the\r
- * texture will be used.\r
+\r
+ /** Helper function to create tiles out of the given {@link Texture} starting from the top left corner going to the left and\r
+ * ending at the bottom right corner. Only complete tiles will be returned so if the texture's width or height are not a\r
+ * multiple of the tile width and height not all of the texture will be used.\r
* \r
* @param texture the Texture\r
* @param tileWidth a tile's width in pixels\r
* @param tileHeight a tile's height in pixels\r
- * @return a 2D array of TextureRegions indexed by [row][column].\r
- */\r
- public static TextureRegion[][] split(Texture texture, int tileWidth, int tileHeight) {\r
+ * @return a 2D array of TextureRegions indexed by [row][column]. */\r
+ public static TextureRegion[][] split (Texture texture, int tileWidth, int tileHeight) {\r
TextureRegion region = new TextureRegion(texture);\r
return region.split(tileWidth, tileHeight);\r
}\r