Package com.sprites

Class MovementSprite

  • Direct Known Subclasses:
    Firetruck, Projectile

    public class MovementSprite
    extends SimpleSprite
    MovementSprite adds movement facilities to a sprite.
    Since:
    08/12/2019
    • Constructor Summary

      Constructors 
      Constructor Description
      MovementSprite​(com.badlogic.gdx.graphics.Texture spriteTexture)
      Creates a sprite capable of moving and but only colliding with other sprites.
      MovementSprite​(com.badlogic.gdx.graphics.Texture spriteTexture, com.badlogic.gdx.maps.tiled.TiledMapTileLayer collisionLayer)
      Creates a sprite capable of moving and colliding with the tiledMap and other sprites.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyAcceleration​(Constants.Direction direction)
      Increases the speed of the sprite in the given direction.
      float getMaxSpeed()
      Returns the max speed the sprite can accelerate to.
      protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.math.Vector2> getPolygonVertices​(com.badlogic.gdx.math.Polygon polygon)
      Gets the coordinates, as Vector2s for each vertex of the polygon
      void setAccelerationRate​(float rate)
      Sets the rate at which the sprite will accelerate.
      void setDecelerationRate​(float rate)
      Sets the rate at which the sprite will decelerate.
      void setMaxSpeed​(float amount)
      Sets the max speed the sprite can accelerate to.
      void setSpeed​(com.badlogic.gdx.math.Vector2 speed)
      Sets the current speed of the sprite.
      void update​(com.badlogic.gdx.graphics.g2d.Batch batch)
      Update the sprite position and direction based on acceleration and boundaries.
      • 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MovementSprite

        public MovementSprite​(com.badlogic.gdx.graphics.Texture spriteTexture,
                              com.badlogic.gdx.maps.tiled.TiledMapTileLayer collisionLayer)
        Creates a sprite capable of moving and colliding with the tiledMap and other sprites.
        Parameters:
        spriteTexture - The texture the sprite should use.
        collisionLayer - The layer of the map the sprite will collide with.
      • MovementSprite

        public MovementSprite​(com.badlogic.gdx.graphics.Texture spriteTexture)
        Creates a sprite capable of moving and but only colliding with other sprites.
        Parameters:
        spriteTexture - The texture the sprite should use.
    • Method Detail

      • update

        public void update​(com.badlogic.gdx.graphics.g2d.Batch batch)
        Update the sprite position and direction based on acceleration and boundaries. This is called every game frame.
        Overrides:
        update in class SimpleSprite
        Parameters:
        batch - The batch to draw onto.
      • applyAcceleration

        public void applyAcceleration​(Constants.Direction direction)
        Increases the speed of the sprite in the given direction.
        Parameters:
        direction - The direction to accelerate in.
      • getPolygonVertices

        protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.math.Vector2> getPolygonVertices​(com.badlogic.gdx.math.Polygon polygon)
        Gets the coordinates, as Vector2s for each vertex of the polygon
        Parameters:
        polygon - to get coordinates of
        Returns:
        list of coordinates
      • setAccelerationRate

        public void setAccelerationRate​(float rate)
        Sets the rate at which the sprite will accelerate.
        Parameters:
        rate - The acceleration rate for the sprite.
      • setDecelerationRate

        public void setDecelerationRate​(float rate)
        Sets the rate at which the sprite will decelerate.
        Parameters:
        rate - The deceleration rate for the sprite.
      • setMaxSpeed

        public void setMaxSpeed​(float amount)
        Sets the max speed the sprite can accelerate to.
        Parameters:
        amount - The max speed value for the sprite.
      • getMaxSpeed

        public float getMaxSpeed()
        Returns the max speed the sprite can accelerate to.
        Returns:
        The max speed value for the sprite.
      • setSpeed

        public void setSpeed​(com.badlogic.gdx.math.Vector2 speed)
        Sets the current speed of the sprite.
        Parameters:
        speed - The speed the sprite should travel.