In LibGDX Is there an actor that is animated (takes an Animation) and when added to a Stage animates itself or do you have to implement your own Image class in and animate it yourself?
I simply created an "AnimatedImage" actor class which only takes an Animation as an argument (no need for a custom Drawable class). I think this solution is much simpler than the one above.
AnimatedImage.java:
public class AnimatedImage extends Image
{
protected Animation animation = null;
private float stateTime = 0;
public AnimatedImage(Animation animation) {
super(animation.getKeyFrame(0));
this.animation = animation;
}
@Override
public void act(float delta)
{
((TextureRegionDrawable)getDrawable()).setRegion(animation.getKeyFrame(stateTime+=delta, true));
super.act(delta);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With