|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.badlogic.gdx.graphics.g2d.TextureRegion com.badlogic.gdx.graphics.g2d.Sprite
public class Sprite
Holds the geometry, color, and texture information for drawing 2D sprites using Batch
. 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
Batch.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 Summary | |
---|---|
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)
Creates a sprite based on a specific TextureRegion, the new sprite's region is a copy of the parameter region - altering one does not affect the other |
|
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. |
Method Summary | |
---|---|
void |
draw(Batch batch)
|
void |
draw(Batch batch,
float alphaModulation)
|
void |
flip(boolean x,
boolean y)
boolean parameters x,y are not setting a state, but performing a flip |
Rectangle |
getBoundingRectangle()
Returns the bounding axis aligned Rectangle that bounds this sprite. |
Color |
getColor()
Returns the color of this sprite. |
float |
getHeight()
|
float |
getOriginX()
The origin influences setPosition(float, float) , setRotation(float) and the expansion direction of scaling
setScale(float, float) |
float |
getOriginY()
The origin influences setPosition(float, float) , setRotation(float) and the expansion direction of scaling
setScale(float, float) |
float |
getRotation()
|
float |
getScaleX()
X scale of the sprite, independent of size set by setSize(float, float) |
float |
getScaleY()
Y scale of the sprite, independent of size set by setSize(float, float) |
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 in degrees 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)
Make this sprite a copy in every way of the specified sprite |
void |
setAlpha(float a)
Sets the alpha portion of the color used to tint this 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 |
setFlip(boolean x,
boolean y)
Set the sprite's flip state regardless of current condition |
void |
setOrigin(float originX,
float originY)
Sets the origin in relation to the sprite's position for scaling and rotation. |
void |
setOriginCenter()
Place origin in the center of the sprite |
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)
Sets the rotation of the sprite in degrees. |
void |
setScale(float scaleXY)
Sets the sprite's scale for both X and Y uniformly. |
void |
setScale(float scaleX,
float scaleY)
Sets the sprite's scale for both X and Y. |
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. |
Methods inherited from class com.badlogic.gdx.graphics.g2d.TextureRegion |
---|
getRegionHeight, getRegionWidth, getRegionX, getRegionY, getTexture, getU, getU2, getV, getV2, isFlipX, isFlipY, setRegion, setRegion, setRegion, setRegion, setRegionHeight, setRegionWidth, setRegionX, setRegionY, setTexture, split, split |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Sprite()
public Sprite(Texture texture)
public Sprite(Texture texture, 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(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)
Method Detail |
---|
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 setAlpha(float a)
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 setOriginCenter()
public void setRotation(float degrees)
setOrigin(float, float)
public float getRotation()
public void rotate(float degrees)
setOrigin(float, float)
public void rotate90(boolean clockwise)
setRotation(float)
and rotate(float)
.
public void setScale(float scaleXY)
getWidth()
and getHeight()
public void setScale(float scaleX, float scaleY)
getWidth()
and getHeight()
public void scale(float amount)
getWidth()
and
getHeight()
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(Batch batch)
public void draw(Batch batch, float alphaModulation)
public float getX()
public float getY()
public float getWidth()
public float getHeight()
public float getOriginX()
setPosition(float, float)
, setRotation(float)
and the expansion direction of scaling
setScale(float, float)
public float getOriginY()
setPosition(float, float)
, setRotation(float)
and the expansion direction of scaling
setScale(float, float)
public float getScaleX()
setSize(float, float)
public float getScaleY()
setSize(float, float)
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 TextureRegion
public void setU(float u)
setU
in class TextureRegion
public void setV(float v)
setV
in class TextureRegion
public void setU2(float u2)
setU2
in class TextureRegion
public void setV2(float v2)
setV2
in class TextureRegion
public void setFlip(boolean x, boolean y)
x
- the desired horizontal flip statey
- the desired vertical flip statepublic void flip(boolean x, boolean y)
flip
in class TextureRegion
x
- perform horizontal flipy
- perform vertical flippublic void scroll(float xAmount, float yAmount)
TextureRegion
scroll
in class TextureRegion
xAmount
- The percentage to offset horizontally.yAmount
- The percentage to offset vertically. This is done in texture space, so up is negative.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |