I am creating an AnimatedImage class that extends Image to automate writing in Image. My code would be like this:
public class AnimatedImage extends Image{ private Array<Array<Sprite>> spriteCollection; private TextureRegionDrawable drawableSprite; private Animation _animation; private boolean isLooping; private float stateTime; private float currentTime; public AnimatedImage(Array<Array<Sprite>> _sprites, float animTime, boolean _looping){
changetosequence method will make a new Animation , which will be used to update the current TextureRegionDrawable using the update method. resetTime will reset the total animation time when calling changetosequence . You can add an event listener to call the changeToSequence method.
Here is an example:
private AnimatedImage _img;
then I add an InputListener as follows:
_img.addListener(new InputListener(){ @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){ _img.changeToSequence(1); return true; } });
Hope this helps.
source share