title: My Stage does not play sprites animation (Libgdx)
body: <p>I am trying to reproduce sprites animation for certain actors in my scenario. In addition to following a book, I was also watching a step-by-step tutorial on how to create with libgdx, a game of "FlappyBird". This is not to say that I´m doing the same thing either than what the guy in the video wants to do.</p>
  
  <p>I´m trying to make a game like "fruit smash" or "bejeweled"... something like that. I create my menu, and my game (or playstate like the tutorial). I create also, a table class (this class extends Stage) that manages the boxes (actors) of the stage. The program already places the boxes in their respective positions and obtains the coordinates of each box so that the moment you click on a box, the game knows which box it is.</p>
  
  <p>Now... I want to reproduce the sprite animation of some boxes... but my table (or stage) does not play the animation.</p>
  
  <p>My Box class is this:</p>
  
  <pre><code>public class Box extends Actor {
  private Tipo tipo;
  private boolean activo;
  private String clase;
  private TextureRegion region;
  private float elapsedTime;
  private Animation&lt;TextureRegion&gt; animacion,selected, unselected;
  private Rectangle area;
  private float velocidadY,velocidadX;
  private int minY,minX,maxY,maxX;
  
  public Box(){
      super();
      velocidadX = 0;
      velocidadY = 0;
      minY = 0;
      minX = 0;
      maxY = 0;
      maxX = 0;
      elapsedTime = 0;
      activo = false;
      region = new TextureRegion();
      area = new Rectangle();
      asignarTipo();
  }
  
  //HERE I ASSIGN THE TYPE OF EACH BOX 
  public void asignarTipo(){
      Random rand = new Random();
      int t = rand.nextInt((4-1)+1)+1;;
      switch (t){
          case 1:
              tipo = Tipo.cbV2;
              clase = "V2";
              unselected = new Animation(0.2f,cargarSprites("1B",".png",1));
              selected = new Animation(0.2f,cargarSprites("1",".png",2),Animation.PlayMode.LOOP_PINGPONG);
              setAnimation(selected);
              break;
          case 2:
              tipo = tipo.cbV4;
              clase = "V4";
              unselected = new Animation(0.2f,cargarSprites("2B",".png",1));
              selected = new Animation(0.2f,cargarSprites("2",".png",2),Animation.PlayMode.LOOP_PINGPONG);
              setAnimation(unselected);
              break;
          case 3:
              tipo = tipo.cbV8;
              clase = "V8";
              unselected = new Animation(0.2f,cargarSprites("3B",".png",1));
              selected = new Animation(0.2f,cargarSprites("3",".png",2),Animation.PlayMode.LOOP_PINGPONG);
              setAnimation(unselected);
              break;
          case 4:
              tipo = tipo.cbV16;
              clase = "V16";
              unselected = new Animation(0.2f,cargarSprites("4B",".png",1));
              selected = new Animation(0.2f,cargarSprites("4",".png",2),Animation.PlayMode.LOOP_PINGPONG);
              setAnimation(unselected);
              break;
      }
  }
  
  //setTexture
  public void setTextura(Texture t){
          int ancho = t.getWidth();
          int alto = t.getHeight();
          setWidth(ancho);
          setHeight(alto);
          region.setRegion(t);
  }
  
  //This function returns the sprite array
  public Array&lt;TextureRegion&gt; cargarSprites(String imagen, String ext, int index){
      TextureRegion frames[] = new TextureRegion[index];
      for (int i = 0; i &lt; index; i++){
          if(imagen.length() &lt; 2){
              Texture t = new Texture(Gdx.files.internal(imagen + i + ext));
              t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
              frames[i] = new TextureRegion(t);
          }else{
              Texture t = new Texture(Gdx.files.internal(imagen + ext));
              t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
              frames[i] = new TextureRegion(t);
          }
      }
      Array&lt;TextureRegion&gt; framesArray = new Array(frames);
      return framesArray;
  }
  
  public void setAnimation(Animation&lt;TextureRegion&gt; a)
  {
      setTextura(a.getKeyFrame(0).getTexture());
      animacion = a;
  }
  
  public Rectangle getBoundingRectangle(){
      area.set(getX(),getY(),getWidth(),getHeight());
      return area;
  }
  
  //Act method (or UPDATE)
  public void Act(float dt){
      super.act(dt);
      elapsedTime += dt;
      moveBy(velocidadX * dt, velocidadY * dt);
  }
  
  public void draw(Batch batch, float parentAlpha){
      Color c = getColor();
      batch.setColor(c.r, c.g, c.b, c.a);
      region.setRegion(animacion.getKeyFrame(elapsedTime));
      if ( isVisible() )
          batch.draw( region, getX(), getY(), getOriginX(), getOriginY(),
                  getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation() );
  }
  }
  </code></pre>
  
  <p>The Table Class:</p>
  
  <pre><code> //I do a loop to render all the boxes of my table
   public void updateTableObjects(float dt){
      for(int f=0;f&lt;baterias.length;f++){
          for(int c=0;c&lt;baterias[f].length;c++){
                baterias[f][c].act(dt);
              }
          }
      }
  </code></pre>
  
  <p>PlayState class:</p>
  
  <pre><code>public class PlayState extends Estado {
  private Texture background;
  private Tabla tabla;
  protected PlayState(GameStateManager gsm) {
      super(gsm);
      tabla = new Tabla();
      background = new Texture("fondo_juego.png");
      camara.setToOrtho(true,background.getWidth(),background.getHeight());
      Image fondo = new Image(background);
  }
  
  @Override
  public void update(float dt) {
      handleInput();
  }
  
  @Override
  public void handleInput() {
      if(Gdx.input.isTouched()){
          raton.set(Gdx.input.getX(), Gdx.input.getY(),0);
          camara.unproject(raton);
          if(raton.x &gt; 173 &amp;&amp; raton.y &lt; 703)
             tabla.buscarCubo(raton.x,raton.y);
          System.out.println((int)raton.x + "," + (int)raton.y);
      }
  }
  
  //I THINK HERE IS THE PROBLEM... I TRY TO PLACE THE METHOD THAT UPDATES
  //ALL THE BOXES OF THE TABLE, BUT DIDNT WORK
  @Override
  public void render(SpriteBatch batch) {
      batch.begin();
      batch.draw(background,0,0, game.ANCHO, game.ALTO);
      batch.end();
      tabla.act(Gdx.graphics.getDeltaTime());
      tabla.updateTableObjects(Gdx.graphics.getDeltaTime());
      tabla.draw();
  }
  }
  </code></pre>
  
  <p>Whats wrong here?</p>