Class AnimatedSprite

java.lang.Object
com.badlogic.gdx.graphics.g2d.TextureRegion
com.badlogic.gdx.graphics.g2d.Sprite
net.dermetfan.gdx.graphics.g2d.AnimatedSprite

public class AnimatedSprite extends com.badlogic.gdx.graphics.g2d.Sprite
An AnimatedSprite holds an Animation and sets the Texture of its super type Sprite to the correct one according to the information in the Animation.
Usage:

Animation animation = new Animation(1 / 3f, frame1, frame2, frame3);
animation.setPlayMode(Animation.LOOP);
animatedSprite = new AnimatedSprite(animation);

You can draw using any of the Sprite's draw methods:
animatedSprite.draw(batch);
  • Constructor Summary

    Constructors
    Constructor
    Description
    AnimatedSprite(com.badlogic.gdx.graphics.g2d.Animation<com.badlogic.gdx.graphics.g2d.TextureRegion> animation)
    creates a new AnimatedSprite with the given Animation
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    draw(com.badlogic.gdx.graphics.g2d.Batch batch)
    Draws this AnimatedSprite.
    void
    flipFrames(boolean flipX, boolean flipY)
    flips all frames
    void
    flipFrames(boolean flipX, boolean flipY, boolean set)
    flips all frames
    void
    flipFrames(float startTime, float endTime, boolean flipX, boolean flipY)
     
    void
    flipFrames(float startTime, float endTime, boolean flipX, boolean flipY, boolean set)
    Flips all frames from startTime to endTime.
    com.badlogic.gdx.graphics.g2d.Animation
     
    float
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    void
    sets playing to false
    void
    sets playing to true
    void
    setAnimation(com.badlogic.gdx.graphics.g2d.Animation animation)
     
    void
    setAutoUpdate(boolean autoUpdate)
     
    void
    setCenterFrames(boolean centerFrames)
     
    void
    setPlaying(boolean playing)
     
    void
    setTime(float time)
     
    void
    setUseFrameRegionSize(boolean useFrameRegionSize)
     
    void
    pauses and sets the time to 0
    void
    updates the AnimatedSprite with the delta time fetched from Gdx.graphics.getDeltaTime()
    void
    update(float delta)
    updates the AnimatedSprite with the given delta time

    Methods inherited from class com.badlogic.gdx.graphics.g2d.Sprite

    draw, flip, getBoundingRectangle, getColor, getHeight, getOriginX, getOriginY, getPackedColor, getRotation, getScaleX, getScaleY, getVertices, getWidth, getX, getY, rotate, rotate90, scale, scroll, set, setAlpha, setBounds, setCenter, setCenterX, setCenterY, setColor, setColor, setFlip, setOrigin, setOriginBasedPosition, setOriginCenter, setPackedColor, setPosition, setRegion, setRotation, setScale, setScale, setSize, 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 Details

    • AnimatedSprite

      public AnimatedSprite(com.badlogic.gdx.graphics.g2d.Animation<com.badlogic.gdx.graphics.g2d.TextureRegion> animation)
      creates a new AnimatedSprite with the given Animation
      Parameters:
      animation - the animation to use
  • Method Details

    • update

      public void update()
      updates the AnimatedSprite with the delta time fetched from Gdx.graphics.getDeltaTime()
    • update

      public void update(float delta)
      updates the AnimatedSprite with the given delta time
    • draw

      public void draw(com.badlogic.gdx.graphics.g2d.Batch batch)
      Draws this AnimatedSprite. If autoUpdate is true, update() will be called before drawing.
      Overrides:
      draw in class com.badlogic.gdx.graphics.g2d.Sprite
    • flipFrames

      public void flipFrames(boolean flipX, boolean flipY)
      flips all frames
      See Also:
    • flipFrames

      public void flipFrames(boolean flipX, boolean flipY, boolean set)
      flips all frames
      See Also:
    • flipFrames

      public void flipFrames(float startTime, float endTime, boolean flipX, boolean flipY)
      See Also:
    • flipFrames

      public void flipFrames(float startTime, float endTime, boolean flipX, boolean flipY, boolean set)
      Flips all frames from startTime to endTime. Note the actual TextureRegions are flipped, so if the animation contains a region more than once, those frames cannot be flipped differently at the same time. Also they will be flipped as often as they occur in the given time range.
      Parameters:
      startTime - the animation state time of the first frame to flip
      endTime - the animation state time of the last frame to flip
      set - if the frames should be set to flipX and flipY instead of actually flipping them
    • play

      public void play()
      sets playing to true
    • pause

      public void pause()
      sets playing to false
    • stop

      public void stop()
      pauses and sets the time to 0
    • setTime

      public void setTime(float time)
      Parameters:
      time - the time to go to
    • getTime

      public float getTime()
      Returns:
      the current time
    • getAnimation

      public com.badlogic.gdx.graphics.g2d.Animation getAnimation()
      Returns:
      the animation
    • setAnimation

      public void setAnimation(com.badlogic.gdx.graphics.g2d.Animation animation)
      Parameters:
      animation - the animation to set
    • isPlaying

      public boolean isPlaying()
      Returns:
      if this AnimatedSprite is playing
    • setPlaying

      public void setPlaying(boolean playing)
      Parameters:
      playing - if the AnimatedSprite should be playing
    • isAnimationFinished

      public boolean isAnimationFinished()
      Returns:
      if the animation has finished playing
    • isAutoUpdate

      public boolean isAutoUpdate()
      Returns:
      the autoUpdate
    • setAutoUpdate

      public void setAutoUpdate(boolean autoUpdate)
      Parameters:
      autoUpdate - the autoUpdate to set
    • isUseFrameRegionSize

      public boolean isUseFrameRegionSize()
      Returns:
      the useFrameRegionSize
    • setUseFrameRegionSize

      public void setUseFrameRegionSize(boolean useFrameRegionSize)
      Parameters:
      useFrameRegionSize - the useFrameRegionSize to set
    • isCenterFrames

      public boolean isCenterFrames()
      Returns:
      the centerFrames
    • setCenterFrames

      public void setCenterFrames(boolean centerFrames)
      Parameters:
      centerFrames - the centerFrames to set