Package com.sprites
Class SimpleSprite
- java.lang.Object
-
- com.badlogic.gdx.graphics.g2d.TextureRegion
-
- com.badlogic.gdx.graphics.g2d.Sprite
-
- com.sprites.SimpleSprite
-
- Direct Known Subclasses:
ETFortress,Firestation,MinigameSprite,MovementSprite,PatrolMovementSprite
public class SimpleSprite extends com.badlogic.gdx.graphics.g2d.SpriteSimplify and add functionality to the sprite object provided by libGDX.- Since:
- 17/12/2019
-
-
Constructor Summary
Constructors Constructor Description SimpleSprite(com.badlogic.gdx.graphics.Texture spriteTexture)Constructor that creates a sprite at a given position using a given texture..
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddecreaseInternalTime()Decrement or reset the internal time of the sprite used for timing of attacksvoiddispose()Dispose of assets used by the class.voiddrawDebug(com.badlogic.gdx.graphics.glutils.ShapeRenderer renderer)Enables drawing of the hitbox to it can be seen.com.badlogic.gdx.math.Vector2getCentre()floatgetCentreX()Get the value of the centre x-coordinate of the sprite.floatgetCentreY()Get the value of the centre y-coordinate of the sprite.com.badlogic.gdx.math.PolygongetDamageHitBox()Get the damage hit box of the sprite.ResourceBargetHealthBar()Get the health bar of the sprite.floatgetHeight()Get the current height of the sprite.floatgetInternalTime()Get the internal time of the sprite.com.badlogic.gdx.math.PolygongetMovementHitBox()Get the movement hit box of the sprite.floatgetWidth()Get the current width of the sprite.voidremoveSprite(com.badlogic.gdx.graphics.Texture destroyedTexture)Enables drawing of the hitbox to it can be seen.voidresetRotation(float degrees)Resets the rotation of the sprite, but also the hit boxesvoidrotate(float degrees)Overrides Sprite class method to rotate the sprite and hitbox at once.voidsetInternalTime(int time)Set the internal time of the sprite.voidsetMovementHitBox(float rotation)Changes the movement hit box to a triangle for better movement and collisionsvoidsetSize(float width, float height)Overrides Sprite class method to keep seperate values for width and height.voidupdate(com.badlogic.gdx.graphics.g2d.Batch batch)Update the sprite position, hitbox and health bar.-
Methods inherited from class com.badlogic.gdx.graphics.g2d.Sprite
draw, draw, flip, getBoundingRectangle, getColor, getOriginX, getOriginY, getRotation, getScaleX, getScaleY, getVertices, getX, getY, rotate90, scale, scroll, set, setAlpha, setBounds, setCenter, setCenterX, setCenterY, setColor, setColor, setFlip, setOrigin, setOriginBasedPosition, setOriginCenter, setPackedColor, setPosition, setRegion, setRotation, setScale, setScale, setU, setU2, setV, setV2, setX, setY, translate, translateX, translateY
-
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
-
-
-
-
Method Detail
-
update
public void update(com.badlogic.gdx.graphics.g2d.Batch batch)
Update the sprite position, hitbox and health bar. Must be called every frame in order to draw the sprite.- Parameters:
batch- The batch to draw onto.
-
decreaseInternalTime
public void decreaseInternalTime()
Decrement or reset the internal time of the sprite used for timing of attacks
-
drawDebug
public void drawDebug(com.badlogic.gdx.graphics.glutils.ShapeRenderer renderer)
Enables drawing of the hitbox to it can be seen.- Parameters:
renderer- The shape renderer to draw onto.
-
removeSprite
public void removeSprite(com.badlogic.gdx.graphics.Texture destroyedTexture)
Enables drawing of the hitbox to it can be seen.- Parameters:
destroyedTexture- The flooded texture to replace the sprite with
-
setSize
public void setSize(float width, float height)Overrides Sprite class method to keep seperate values for width and height. Also updates the sprites width and height and creates a new hitbox and health bar.- Overrides:
setSizein classcom.badlogic.gdx.graphics.g2d.Sprite- Parameters:
width- The width the sprite should be set to.height- The height the sprite should be set to.
-
setMovementHitBox
public void setMovementHitBox(float rotation)
Changes the movement hit box to a triangle for better movement and collisions- Parameters:
rotation- amount in degrees to rotate the hitbox by
-
rotate
public void rotate(float degrees)
Overrides Sprite class method to rotate the sprite and hitbox at once.- Overrides:
rotatein classcom.badlogic.gdx.graphics.g2d.Sprite- Parameters:
degrees- The degree to rotate to.
-
resetRotation
public void resetRotation(float degrees)
Resets the rotation of the sprite, but also the hit boxes- Parameters:
degrees- what the starting rotation should be
-
getHealthBar
public ResourceBar getHealthBar()
Get the health bar of the sprite.- Returns:
- The health bar of the sprite.
-
getInternalTime
public float getInternalTime()
Get the internal time of the sprite.- Returns:
- The internal time of the sprite.
-
setInternalTime
public void setInternalTime(int time)
Set the internal time of the sprite.- Parameters:
time- new internal time
-
getMovementHitBox
public com.badlogic.gdx.math.Polygon getMovementHitBox()
Get the movement hit box of the sprite.- Returns:
- The hit box of the sprite.
-
getDamageHitBox
public com.badlogic.gdx.math.Polygon getDamageHitBox()
Get the damage hit box of the sprite.- Returns:
- The hit box of the sprite.
-
getWidth
public float getWidth()
Get the current width of the sprite.- Overrides:
getWidthin classcom.badlogic.gdx.graphics.g2d.Sprite- Returns:
- The width of the sprite.
-
getHeight
public float getHeight()
Get the current height of the sprite.- Overrides:
getHeightin classcom.badlogic.gdx.graphics.g2d.Sprite- Returns:
- The height of the sprite.
-
getCentreX
public float getCentreX()
Get the value of the centre x-coordinate of the sprite.- Returns:
- The cente X-coordinate of the sprite.
-
getCentreY
public float getCentreY()
Get the value of the centre y-coordinate of the sprite.- Returns:
- The centre y-coordinate of the sprite.
-
getCentre
public com.badlogic.gdx.math.Vector2 getCentre()
-
dispose
public void dispose()
Dispose of assets used by the class.
-
-