Class GameSpaceSprite
- java.lang.Object
-
- com.badlogic.gdx.graphics.g2d.TextureRegion
-
- com.bombinggames.wurfelengine.core.map.rendering.GameSpaceSprite
-
public class GameSpaceSprite extends com.badlogic.gdx.graphics.g2d.TextureRegion
-
-
Constructor Summary
Constructors Constructor Description GameSpaceSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion region)
Creates a sprite based on a specific TextureRegion, the new sprite's region is a cospy of the parameter region - altering one does not affect the otherGameSpaceSprite(com.badlogic.gdx.graphics.g2d.TextureRegion region, Side side, byte aoFlags)
An object helping with rendering a blokc made out of sides
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyAO()
apply the ao to the vertice colorvoid
draw(com.badlogic.gdx.graphics.g2d.Batch batch)
void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, float alphaModulation)
void
flip(boolean x, boolean y)
boolean parameters x,y are not setting a state, but performing a flipcom.badlogic.gdx.math.Rectangle
getBoundingRectangle()
Returns the bounding axis alignedRectangle
that bounds this sprite.com.badlogic.gdx.graphics.Color
getColor()
Returns the color of this sprite.float
getHeight()
float
getOriginX()
The origin influencessetPosition(float, float, float)
,setRotation(float)
and the expansion direction of scalingsetScale(float, float)
float
getOriginY()
The origin influencessetPosition(float, float, float)
,setRotation(float)
and the expansion direction of scalingsetScale(float, float)
float
getRotation()
float
getScaleX()
X scale of the sprite, independent of size set bysetSize(float, float)
float
getScaleY()
Y scale of the sprite, independent of size set bysetSize(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. for example: original scale 2 -> sprite.scale(4) -> final scale 6.void
scroll(float xAmount, float yAmount)
void
setAlpha(float a)
Sets the alpha portion of the color used to tint this sprite.static void
setAO(float brightness)
void
setAoFlags(byte aoFlags)
Flags can be used with every sprites but are expected only with block spritesvoid
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 parametervoid
setCenterY(float y)
Sets the y position so that it is centered on the given y parametervoid
setColor(float color)
Sets the color to each vertice.void
setColor(float r, float g, float b, float a)
void
setColor(float v1r, float v1g, float v1b, float v2r, float v2g, float v2b, float v3r, float v3g, float v3b, float v4r, float v4g, float v4b)
Sets the color used to tint this sprite.void
setColor(com.badlogic.gdx.graphics.Color tint)
Sets the color used to tint this sprite.void
setFlip(boolean x, boolean y)
Set the sprite's flip state regardless of current conditionvoid
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 spritevoid
setPosition(float x, float y, float z)
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, float zAmount)
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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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
-
-
-
-
Constructor Detail
-
GameSpaceSprite
public GameSpaceSprite(com.badlogic.gdx.graphics.g2d.TextureRegion region, Side side, byte aoFlags)
An object helping with rendering a blokc made out of sides- Parameters:
region
- the texture used for rendering this sideside
- which side does this represent?, if null is no block sideaoFlags
- uses one byte for a side
-
GameSpaceSprite
public GameSpaceSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion region)
Creates a sprite based on a specific TextureRegion, the new sprite's region is a cospy of the parameter region - altering one does not affect the other- Parameters:
region
-
-
-
Method Detail
-
setAO
public static void setAO(float brightness)
- Parameters:
brightness
-
-
setBounds
public 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. If origin, rotation, or scale are changed, it is slightly more efficient to set the bounds after those operations.- Parameters:
x
-height
-width
-y
-
-
setSize
public void setSize(float width, float height)
Sets the size of the sprite when drawn, before scaling and rotation are applied. If origin, rotation, or scale are changed, it is slightly more efficient to set the size after those operations. If both position and size are to be changed, it is better to usesetBounds(float, float, float, float)
.- Parameters:
width
-height
- view space
-
setPosition
public void setPosition(float x, float y, float z)
Sets the position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient to set the position after those operations. If both position and size are to be changed, it is better to usesetBounds(float, float, float, float)
.- Parameters:
x
- game spacey
- game spacez
- game space
-
setX
public void setX(float x)
Sets the x position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient to set the position after those operations. If both position and size are to be changed, it is better to usesetBounds(float, float, float, float)
.- Parameters:
x
-
-
setY
public void setY(float y)
Sets the y position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient to set the position after those operations. If both position and size are to be changed, it is better to usesetBounds(float, float, float, float)
.- Parameters:
y
-
-
setCenterX
public void setCenterX(float x)
Sets the x position so that it is centered on the given x parameter- Parameters:
x
-
-
setCenterY
public void setCenterY(float y)
Sets the y position so that it is centered on the given y parameter- Parameters:
y
-
-
setCenter
public void setCenter(float x, float y)
Sets the position so that the sprite is centered on (x, y)- Parameters:
x
-y
-
-
translateX
public void translateX(float xAmount)
Sets the x position relative to the current position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient to translate after those operations.- Parameters:
xAmount
-
-
translateY
public void translateY(float yAmount)
Sets the y position relative to the current position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient to translate after those operations.- Parameters:
yAmount
-
-
translate
public void translate(float xAmount, float yAmount, float zAmount)
Sets the position relative to the current position where the sprite will be drawn. If origin, rotation, or scale are changed, it is slightly more efficient to translate after those operations.- Parameters:
xAmount
-yAmount
-zAmount
-
-
setColor
public void setColor(float v1r, float v1g, float v1b, float v2r, float v2g, float v2b, float v3r, float v3g, float v3b, float v4r, float v4g, float v4b)
Sets the color used to tint this sprite. Default isColor.WHITE
.- Parameters:
v1r
-v1g
-v1b
-v2r
-v2g
-v2b
-v3r
-v3g
-v3b
-v4r
-v4g
-v4b
-
-
setAlpha
public void setAlpha(float a)
Sets the alpha portion of the color used to tint this sprite.- Parameters:
a
-
-
setColor
public void setColor(float r, float g, float b, float a)
- Parameters:
r
- * @see #setColor(Color)g
-b
-a
-
-
setColor
public void setColor(float color)
Sets the color to each vertice.- Parameters:
color
-- See Also:
Color.toFloatBits()
-
setColor
public void setColor(com.badlogic.gdx.graphics.Color tint)
Sets the color used to tint this sprite. Default isColor.WHITE
.- Parameters:
tint
-
-
setOrigin
public void setOrigin(float originX, float originY)
Sets the origin in relation to the sprite's position for scaling and rotation.- Parameters:
originX
-originY
-
-
setOriginCenter
public void setOriginCenter()
Place origin in the center of the sprite
-
setRotation
public void setRotation(float degrees)
Sets the rotation of the sprite in degrees. Rotation is centered on the origin set insetOrigin(float, float)
- Parameters:
degrees
-
-
getRotation
public float getRotation()
- Returns:
- the rotation of the sprite in degrees
-
rotate
public void rotate(float degrees)
Sets the sprite's rotation in degrees relative to the current rotation. Rotation is centered on the origin set insetOrigin(float, float)
- Parameters:
degrees
-
-
rotate90
public void rotate90(boolean clockwise)
Rotates this sprite 90 degrees in-place by rotating the texture coordinates. This rotation is unaffected bysetRotation(float)
androtate(float)
.- Parameters:
clockwise
-
-
setScale
public void setScale(float scaleXY)
Sets the sprite's scale for both X and Y uniformly. The sprite scales out from the origin. This will not affect the values returned bygetWidth()
andgetHeight()
- Parameters:
scaleXY
-
-
setScale
public void setScale(float scaleX, float scaleY)
Sets the sprite's scale for both X and Y. The sprite scales out from the origin. This will not affect the values returned bygetWidth()
andgetHeight()
- Parameters:
scaleX
-scaleY
-
-
scale
public void scale(float amount)
Sets the sprite's scale relative to the current scale. for example: original scale 2 -> sprite.scale(4) -> final scale 6. The sprite scales out from the origin. This will not affect the values returned bygetWidth()
andgetHeight()
- Parameters:
amount
-
-
getVertices
public float[] getVertices()
Returns the packed vertices, colors, and texture coordinates for this sprite.- Returns:
-
applyAO
protected void applyAO()
apply the ao to the vertice color
-
getBoundingRectangle
public com.badlogic.gdx.math.Rectangle getBoundingRectangle()
Returns the bounding axis alignedRectangle
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.- Returns:
- the bounding Rectangle
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch)
- Parameters:
batch
-
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float alphaModulation)
- Parameters:
batch
-alphaModulation
-
-
getX
public float getX()
- Returns:
-
getY
public float getY()
- Returns:
-
getWidth
public float getWidth()
- Returns:
- the width of the sprite, not accounting for scale.
-
getHeight
public float getHeight()
- Returns:
- the height of the sprite, not accounting for scale.
-
getOriginX
public float getOriginX()
The origin influencessetPosition(float, float, float)
,setRotation(float)
and the expansion direction of scalingsetScale(float, float)
- Returns:
-
getOriginY
public float getOriginY()
The origin influencessetPosition(float, float, float)
,setRotation(float)
and the expansion direction of scalingsetScale(float, float)
- Returns:
-
getScaleX
public float getScaleX()
X scale of the sprite, independent of size set bysetSize(float, float)
- Returns:
-
getScaleY
public float getScaleY()
Y scale of the sprite, independent of size set bysetSize(float, float)
- Returns:
-
getColor
public com.badlogic.gdx.graphics.Color getColor()
Returns the color of this sprite. Changing the returned color will have no affect,setColor(float)
orsetColor(float, float, float, float)
must be used.- Returns:
-
setRegion
public void setRegion(float u, float v, float u2, float v2)
- Overrides:
setRegion
in classcom.badlogic.gdx.graphics.g2d.TextureRegion
-
setU
public void setU(float u)
- Overrides:
setU
in classcom.badlogic.gdx.graphics.g2d.TextureRegion
-
setV
public void setV(float v)
- Overrides:
setV
in classcom.badlogic.gdx.graphics.g2d.TextureRegion
- Parameters:
v
-
-
setU2
public void setU2(float u2)
- Overrides:
setU2
in classcom.badlogic.gdx.graphics.g2d.TextureRegion
- Parameters:
u2
-
-
setV2
public void setV2(float v2)
- Overrides:
setV2
in classcom.badlogic.gdx.graphics.g2d.TextureRegion
- Parameters:
v2
-
-
setFlip
public void setFlip(boolean x, boolean y)
Set the sprite's flip state regardless of current condition- Parameters:
x
- the desired horizontal flip statey
- the desired vertical flip state
-
flip
public void flip(boolean x, boolean y)
boolean parameters x,y are not setting a state, but performing a flip- Overrides:
flip
in classcom.badlogic.gdx.graphics.g2d.TextureRegion
- Parameters:
x
- perform horizontal flipy
- perform vertical flip
-
scroll
public void scroll(float xAmount, float yAmount)
- Overrides:
scroll
in classcom.badlogic.gdx.graphics.g2d.TextureRegion
-
setAoFlags
public void setAoFlags(byte aoFlags)
Flags can be used with every sprites but are expected only with block sprites- Parameters:
aoFlags
-
-
-