public class Sprite extends TextureRegion
SpriteBatch. A Sprite has a position
and a size given as width and height. The position is relative to the origin of the coordinate system specified via
SpriteBatch.begin() and the respective matrices. A Sprite is always rectangular and its position (x, y) are located in
the bottom left corner of that rectangle. A Sprite also has an origin around which rotations and scaling are performed (that
is, the origin is not modified by rotation and scaling). The origin is given relative to the bottom left corner of the Sprite,
its position.| Constructor and Description |
|---|
Sprite()
Creates an uninitialized sprite.
|
Sprite(Sprite sprite)
Creates a sprite that is a copy in every way of the specified sprite.
|
Sprite(Texture texture)
Creates a sprite with width, height, and texture region equal to the size of the texture.
|
Sprite(Texture texture,
int srcWidth,
int srcHeight)
Creates a sprite with width, height, and texture region equal to the specified size.
|
Sprite(Texture texture,
int srcX,
int srcY,
int srcWidth,
int srcHeight)
Creates a sprite with width, height, and texture region equal to the specified size.
|
Sprite(TextureRegion region) |
Sprite(TextureRegion region,
int srcX,
int srcY,
int srcWidth,
int srcHeight)
Creates a sprite with width, height, and texture region equal to the specified size, relative to specified sprite's texture
region.
|
| Modifier and Type | Method and Description |
|---|---|
void |
draw(SpriteBatch spriteBatch) |
void |
draw(SpriteBatch spriteBatch,
float alphaModulation) |
void |
flip(boolean x,
boolean y) |
Rectangle |
getBoundingRectangle()
Returns the bounding axis aligned
Rectangle that bounds this sprite. |
Color |
getColor()
Returns the color of this sprite.
|
float |
getHeight() |
float |
getOriginX() |
float |
getOriginY() |
float |
getRotation() |
float |
getScaleX() |
float |
getScaleY() |
float[] |
getVertices()
Returns the packed vertices, colors, and texture coordinates for this sprite.
|
float |
getWidth() |
float |
getX() |
float |
getY() |
void |
rotate(float degrees)
Sets the sprite's rotation relative to the current rotation.
|
void |
rotate90(boolean clockwise)
Rotates this sprite 90 degrees in-place by rotating the texture coordinates.
|
void |
scale(float amount)
Sets the sprite's scale relative to the current scale.
|
void |
scroll(float xAmount,
float yAmount)
Offsets the region relative to the current region.
|
void |
set(Sprite sprite) |
void |
setBounds(float x,
float y,
float width,
float height)
Sets the position and size of the sprite when drawn, before scaling and rotation are applied.
|
void |
setColor(Color tint)
Sets the color used to tint this sprite.
|
void |
setColor(float color) |
void |
setColor(float r,
float g,
float b,
float a) |
void |
setOrigin(float originX,
float originY)
Sets the origin in relation to the sprite's position for scaling and rotation.
|
void |
setPosition(float x,
float y)
Sets the position where the sprite will be drawn.
|
void |
setRegion(float u,
float v,
float u2,
float v2) |
void |
setRotation(float degrees) |
void |
setScale(float scaleXY) |
void |
setScale(float scaleX,
float scaleY) |
void |
setSize(float width,
float height)
Sets the size of the sprite when drawn, before scaling and rotation are applied.
|
void |
setU(float u) |
void |
setU2(float u2) |
void |
setV(float v) |
void |
setV2(float v2) |
void |
setX(float x)
Sets the x position where the sprite will be drawn.
|
void |
setY(float y)
Sets the y position where the sprite will be drawn.
|
void |
translate(float xAmount,
float yAmount)
Sets the position relative to the current position where the sprite will be drawn.
|
void |
translateX(float xAmount)
Sets the x position relative to the current position where the sprite will be drawn.
|
void |
translateY(float yAmount)
Sets the y position relative to the current position where the sprite will be drawn.
|
getRegionHeight, getRegionWidth, getRegionX, getRegionY, getTexture, getU, getU2, getV, getV2, isFlipX, isFlipY, setRegion, setRegion, setRegion, setRegion, setRegionHeight, setRegionWidth, setRegionX, setRegionY, setTexture, split, splitpublic Sprite()
public Sprite(Texture texture)
public Sprite(Texture texture, int srcWidth, int srcHeight)
srcHeight - The height of the texture region. May be negative to flip the sprite when drawn.public Sprite(Texture texture, int srcX, int srcY, int srcWidth, int srcHeight)
srcWidth - The width of the texture region. May be negative to flip the sprite when drawn.srcHeight - The height of the texture region. May be negative to flip the sprite when drawn.public Sprite(TextureRegion region)
public Sprite(TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight)
srcWidth - The width of the texture region. May be negative to flip the sprite when drawn.srcHeight - The height of the texture region. May be negative to flip the sprite when drawn.public Sprite(Sprite sprite)
public void set(Sprite sprite)
public void setBounds(float x,
float y,
float width,
float height)
public void setSize(float width,
float height)
setBounds(float, float, float, float).public void setPosition(float x,
float y)
setBounds(float, float, float, float).public void setX(float x)
setBounds(float, float, float, float).public void setY(float y)
setBounds(float, float, float, float).public void translateX(float xAmount)
public void translateY(float yAmount)
public void translate(float xAmount,
float yAmount)
public void setColor(Color tint)
Color.WHITE.public void setColor(float r,
float g,
float b,
float a)
setColor(Color)public void setColor(float color)
setColor(Color),
Color.toFloatBits()public void setOrigin(float originX,
float originY)
public void setRotation(float degrees)
public void rotate(float degrees)
public void rotate90(boolean clockwise)
setRotation(float) and rotate(float).public void setScale(float scaleXY)
public void setScale(float scaleX,
float scaleY)
public void scale(float amount)
public float[] getVertices()
public Rectangle getBoundingRectangle()
Rectangle that bounds this sprite. The rectangles x and y coordinates describe its
bottom left corner. If you change the position or size of the sprite, you have to fetch the triangle again for it to be
recomputed.public void draw(SpriteBatch spriteBatch)
public void draw(SpriteBatch spriteBatch, float alphaModulation)
public float getX()
public float getY()
public float getWidth()
public float getHeight()
public float getOriginX()
public float getOriginY()
public float getRotation()
public float getScaleX()
public float getScaleY()
public Color getColor()
setColor(Color) or
setColor(float, float, float, float) must be used.public void setRegion(float u,
float v,
float u2,
float v2)
setRegion in class TextureRegionpublic void setU(float u)
setU in class TextureRegionpublic void setV(float v)
setV in class TextureRegionpublic void setU2(float u2)
setU2 in class TextureRegionpublic void setV2(float v2)
setV2 in class TextureRegionpublic void flip(boolean x,
boolean y)
flip in class TextureRegionpublic void scroll(float xAmount,
float yAmount)
TextureRegionscroll in class TextureRegionxAmount - The percentage to offset horizontally.yAmount - The percentage to offset vertically. This is done in texture space, so up is negative.