public class LibgdxSprite extends java.lang.Object implements Sprite
Modifier and Type | Field and Description |
---|---|
com.badlogic.gdx.graphics.g2d.Sprite |
sprite |
Constructor and Description |
---|
LibgdxSprite()
Creates an uninitialized sprite.
|
LibgdxSprite(Sprite sprite)
Creates a sprite that is a copy in every way of the specified sprite.
|
LibgdxSprite(Texture texture)
Creates a sprite with width, height, and texture region equal to the size
of the texture.
|
LibgdxSprite(Texture texture,
int srcWidth,
int srcHeight)
Creates a sprite with width, height, and texture region equal to the
specified size.
|
LibgdxSprite(Texture texture,
int srcX,
int srcY,
int srcWidth,
int srcHeight)
Creates a sprite with width, height, and texture region equal to the
specified size.
|
LibgdxSprite(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
|
LibgdxSprite(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 |
flip(boolean x,
boolean y) |
float |
getAlpha() |
Rectangle |
getBoundingRectangle()
Returns the bounding axis aligned
Rectangle that bounds this sprite. |
float |
getHeight() |
float |
getOriginX()
The origin influences
Sprite.setPosition(float, float) , Sprite.setRotation(float) and the expansion direction of scaling
Sprite.setScale(float, float) |
float |
getOriginY()
The origin influences
Sprite.setPosition(float, float) , Sprite.setRotation(float) and the expansion direction of scaling
Sprite.setScale(float, float) |
int |
getRegionHeight()
Returns the region's height.
|
int |
getRegionWidth()
Returns the region's width.
|
int |
getRegionX() |
int |
getRegionY() |
float |
getRotation() |
float |
getScaleX()
X scale of the sprite, independent of size set by
Sprite.setSize(float, float) |
float |
getScaleY()
Y scale of the sprite, independent of size set by
Sprite.setSize(float, float) |
Texture |
getTexture() |
Color |
getTint()
Returns the color of this sprite.
|
float |
getU() |
float |
getU2() |
float |
getV() |
float |
getV2() |
float[] |
getVertices()
Returns the packed vertices, colors, and texture coordinates for this sprite.
|
float |
getWidth() |
float |
getX() |
float |
getY() |
boolean |
isFlipX() |
boolean |
isFlipY() |
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) |
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 |
setCenter(float x,
float y)
Sets the position so that the sprite is centered on (x, y)
|
void |
setCenterX(float x)
Sets the x position so that it is centered on the given x parameter
|
void |
setCenterY(float y)
Sets the y position so that it is centered on the given y parameter
|
void |
setFlip(boolean x,
boolean y)
Set the sprite's flip state regardless of current condition
|
void |
setFlipX(boolean flipX) |
void |
setFlipY(boolean flipY) |
void |
setOrigin(float originX,
float originY)
Sets the origin in relation to the sprite's position for scaling and rotation.
|
void |
setOriginBasedPosition(float x,
float y)
Sets the position where the sprite will be drawn, relative to its current origin.
|
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 |
setRegion(int x,
int y,
int width,
int height) |
void |
setRegion(Texture texture) |
void |
setRegion(TextureRegion region)
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 |
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 |
setTexture(Texture texture) |
void |
setTint(Color tint)
Sets the color used to tint this sprite.
|
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.
|
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.
|
Pixmap |
toPixmap()
Converts this
TextureRegion to a Pixmap |
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.
|
public LibgdxSprite()
public LibgdxSprite(Texture texture)
public LibgdxSprite(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 LibgdxSprite(Texture texture, int srcX, int srcY, int srcWidth, int srcHeight)
srcX
- The x coordinate of the region to drawsrcY
- The y coordinate of the region to drawsrcWidth
- 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 LibgdxSprite(TextureRegion region)
public LibgdxSprite(TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight)
srcX
- The x coordinate of the region to drawsrcY
- The y coordinate of the region to drawsrcWidth
- 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 LibgdxSprite(Sprite sprite)
public void setBounds(float x, float y, float width, float height)
Sprite
public void setSize(float width, float height)
Sprite
Sprite.setBounds(float, float, float, float)
.public void setPosition(float x, float y)
Sprite
Sprite.setBounds(float, float, float, float)
.setPosition
in interface Sprite
public void setOriginBasedPosition(float x, float y)
Sprite
setOriginBasedPosition
in interface Sprite
public void setCenterX(float x)
Sprite
setCenterX
in interface Sprite
public void setCenterY(float y)
Sprite
setCenterY
in interface Sprite
public void setCenter(float x, float y)
Sprite
public void translateX(float xAmount)
Sprite
translateX
in interface Sprite
public void translateY(float yAmount)
Sprite
translateY
in interface Sprite
public void translate(float xAmount, float yAmount)
Sprite
public void setOrigin(float originX, float originY)
Sprite
public void setOriginCenter()
Sprite
setOriginCenter
in interface Sprite
public float getRotation()
getRotation
in interface Sprite
public void setRotation(float degrees)
Sprite
Sprite.setOrigin(float, float)
setRotation
in interface Sprite
public void rotate(float degrees)
Sprite
Sprite.setOrigin(float, float)
public void rotate90(boolean clockwise)
Sprite
Sprite.setRotation(float)
and Sprite.rotate(float)
.public void setScale(float scaleXY)
Sprite
Sprite.getWidth()
and Sprite.getHeight()
public void setScale(float scaleX, float scaleY)
Sprite
Sprite.getWidth()
and Sprite.getHeight()
public void scale(float amount)
Sprite
Sprite.getWidth()
and
Sprite.getHeight()
public float[] getVertices()
Sprite
getVertices
in interface Sprite
public Rectangle getBoundingRectangle()
Sprite
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.getBoundingRectangle
in interface Sprite
public void setX(float x)
Sprite
Sprite.setBounds(float, float, float, float)
.public void setY(float y)
Sprite
Sprite.setBounds(float, float, float, float)
.public float getWidth()
public float getHeight()
public float getOriginX()
Sprite
Sprite.setPosition(float, float)
, Sprite.setRotation(float)
and the expansion direction of scaling
Sprite.setScale(float, float)
getOriginX
in interface Sprite
public float getOriginY()
Sprite
Sprite.setPosition(float, float)
, Sprite.setRotation(float)
and the expansion direction of scaling
Sprite.setScale(float, float)
getOriginY
in interface Sprite
public float getScaleX()
Sprite
Sprite.setSize(float, float)
public float getScaleY()
Sprite
Sprite.setSize(float, float)
public Color getTint()
Sprite
public void setTint(Color tint)
Sprite
public void setRegion(Texture texture)
setRegion
in interface TextureRegion
public void setRegion(int x, int y, int width, int height)
setRegion
in interface TextureRegion
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.public void setRegion(float u, float v, float u2, float v2)
setRegion
in interface TextureRegion
public void setRegion(TextureRegion region)
TextureRegion
setRegion
in interface TextureRegion
public void setRegion(TextureRegion region, int x, int y, int width, int height)
TextureRegion
setRegion
in interface TextureRegion
public Texture getTexture()
getTexture
in interface TextureRegion
public void setTexture(Texture texture)
setTexture
in interface TextureRegion
public float getU()
getU
in interface TextureRegion
public void setU(float u)
setU
in interface TextureRegion
public float getV()
getV
in interface TextureRegion
public void setV(float v)
setV
in interface TextureRegion
public float getU2()
getU2
in interface TextureRegion
public void setU2(float u2)
setU2
in interface TextureRegion
public float getV2()
getV2
in interface TextureRegion
public void setV2(float v2)
setV2
in interface TextureRegion
public int getRegionX()
getRegionX
in interface TextureRegion
public void setRegionX(int x)
setRegionX
in interface TextureRegion
public int getRegionY()
getRegionY
in interface TextureRegion
public void setRegionY(int y)
setRegionY
in interface TextureRegion
public int getRegionWidth()
TextureRegion
getRegionWidth
in interface TextureRegion
public void setRegionWidth(int width)
setRegionWidth
in interface TextureRegion
public int getRegionHeight()
TextureRegion
getRegionHeight
in interface TextureRegion
public void setRegionHeight(int height)
setRegionHeight
in interface TextureRegion
public void flip(boolean x, boolean y)
flip
in interface TextureRegion
public void setFlip(boolean x, boolean y)
Sprite
setFlip
in interface Sprite
setFlip
in interface TextureRegion
x
- the desired horizontal flip statey
- the desired vertical flip statepublic boolean isFlipX()
isFlipX
in interface TextureRegion
public void setAlpha(float a)
Sprite
public void setFlipX(boolean flipX)
setFlipX
in interface Sprite
setFlipX
in interface TextureRegion
public boolean isFlipY()
isFlipY
in interface TextureRegion
public void setFlipY(boolean flipY)
setFlipY
in interface Sprite
setFlipY
in interface TextureRegion
public void scroll(float xAmount, float yAmount)
TextureRegion
scroll
in interface TextureRegion
xAmount
- The percentage to offset horizontally.yAmount
- The percentage to offset vertically. This is done in texture space, so up is negative.public Pixmap toPixmap()
TextureRegion
TextureRegion
to a Pixmap
toPixmap
in interface TextureRegion
Pixmap
instance containing the pixel datapublic TextureRegion[][] split(int tileWidth, int tileHeight)
TextureRegion
split
in interface TextureRegion
tileWidth
- a tile's width in pixelstileHeight
- a tile's height in pixels