Class AnimatedGlidingSprite

java.lang.Object
com.badlogic.gdx.graphics.g2d.TextureRegion
com.github.yellowstonegames.smooth.ParentSprite
com.github.yellowstonegames.smooth.AnimatedGlidingSprite

public class AnimatedGlidingSprite extends ParentSprite
Extends Sprite, but uses an Animation of TextureRegion for its visuals and a CoordGlider to store its position. The CoordGlider is publicly available as location or with getLocation(), which should be used to determine or change where this started its move, where it is going, and how far it has gone between the two. You Must Call animate(float) with an increasing float parameter when you want the animation to be playing; otherwise it will stay on the first frame (or a later frame if you stop calling animate() at some other point). You can use the VectorSequenceGlider smallMotion to move this Sprite at a finer resolution than between Coords for start and end points.
You probably want to use Textures with a width and height of 1 world unit in your Animation, and ParentSprite.setSize(float, float) on this to 1, 1; this avoids the need to convert between Coord units in the CoordGlider and some other unit in the world.
  • Field Details

    • animation

      public com.badlogic.gdx.graphics.g2d.Animation<? extends com.badlogic.gdx.graphics.g2d.TextureRegion> animation
    • location

      public CoordGlider location
    • smallMotion

      public VectorSequenceGlider smallMotion
    • ownEmptyMotion

      public final VectorSequenceGlider ownEmptyMotion
      A VectorSequenceGlider that is empty (has no motions) and belongs to this AnimatedGlidingSprite. This is public so external code can use it, but should never be modified. It is here so smallMotion can be easily set to an empty sequence. You can also use setSmallMotion(null) to stop any small motion.
  • Constructor Details

    • AnimatedGlidingSprite

      public AnimatedGlidingSprite(com.badlogic.gdx.graphics.g2d.Animation<? extends com.badlogic.gdx.graphics.g2d.TextureRegion> animation)
    • AnimatedGlidingSprite

      public AnimatedGlidingSprite(com.badlogic.gdx.graphics.g2d.Animation<? extends com.badlogic.gdx.graphics.g2d.TextureRegion> animation, com.github.yellowstonegames.grid.Coord coord)
    • AnimatedGlidingSprite

      public AnimatedGlidingSprite(com.badlogic.gdx.graphics.g2d.Animation<? extends com.badlogic.gdx.graphics.g2d.TextureRegion> animation, com.github.yellowstonegames.grid.Coord start, com.github.yellowstonegames.grid.Coord end)
  • Method Details

    • animate

      public AnimatedGlidingSprite animate(float stateTime)
      Required to use to have the animation play; give this a steadily increasing stateTime (measured in seconds, as a float) and it will steadily play the animation; if stateTime stops increasing or this stops being called, then the animation is effectively paused.
      Parameters:
      stateTime - time playing the animation, in seconds; usually not an exact integer
      Returns:
      this for chaining
    • getX

      public float getX()
      Overrides:
      getX in class ParentSprite
    • getY

      public float getY()
      Overrides:
      getY in class ParentSprite
    • getVertices

      public float[] getVertices()
      Description copied from class: ParentSprite
      Returns the packed vertices, colors, and texture coordinates for this sprite.
      Overrides:
      getVertices in class ParentSprite
    • getAnimation

      public com.badlogic.gdx.graphics.g2d.Animation<? extends com.badlogic.gdx.graphics.g2d.TextureRegion> getAnimation()
    • setAnimation

      public void setAnimation(com.badlogic.gdx.graphics.g2d.Animation<? extends com.badlogic.gdx.graphics.g2d.TextureRegion> animation)
    • getLocation

      public CoordGlider getLocation()
    • setLocation

      public void setLocation(CoordGlider location)
    • getSmallMotion

      public VectorSequenceGlider getSmallMotion()
    • setSmallMotion

      public void setSmallMotion(VectorSequenceGlider smallMotion)