1
\$\begingroup\$

I'm having trouble inserting animation into my libGDX table cell. I have a class which holds 2 tables, one on the left and one on the right. First table is for labels/buttons/other stuff. Second table is for animation, which should change if user clicks a button.

I've created Animation class which holds up different animations. The problem is that when I try to add an animation class into the table cell, I get an error because my Animation does not extend nor implement Actor class, thus I can't insert it into the cell. What should I do? How do you insert class of type animation into table cell?

\$\endgroup\$

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0
\$\begingroup\$

You probably want to extend the Image class yourself and implement the Act method to update the animation state time.

public class Animation extends Image{    
    private float stateTime = 0;
    private Animation<TextureRegion> animation;

   public AnimatedActor(Animation<TextureRegion> anim) {
     super(animation.getKeyFrame(0));
     animation = anim;
   }

   @Override
   public void act(float delta){
  ((TextureRegionDrawable)getDrawable()).setRegion(animation.getKeyFrame(stateTime+=delta, true));
super.act(delta);
      }
 }

If you want more control over the animation you could even oerride the draw method and draw it yourself.

@Override
draw(Batch batch, float parentAlpha){
   // draw your animation here
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.