Search code examples
javalibgdxscene2d

How to make UI animation in Scene2d?


I am using a table in libgdx scene2d to group my labels for my score:

lblScore = new Label("Score: " + Integer.toString(score), labelStyle);
        lblBscore = new Label("Best: " + Integer.toString(bScore), labelStyle);

        table = new Table();
        table.setFillParent(true);
        table.setDebug(false);

        table.top();
        table.add(lblScore).padTop(Constant.HEIGHT / 2 - 100);
        table.row();
        table.add(lblBscore).padTop(10);
        stage.addActor(table);

What I want to happen is that when my character dies the table will show up with an animation, also is it a good idea that while my character is alive the table is just hidden? or should I just create the table when my character dies?


Solution

  • You didn't specify what kind of animation you wanted to do, but check out the Actions class as it has a bunch of actions you can use for animating Scene2d components (move, color change, fade in/out, rotate, etc):

    https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/actions/Actions.html

    And here is a tutorial with example code that demonstrates how to use the Actions:

    http://www.gamefromscratch.com/post/2013/12/09/LibGDX-Tutorial-9-Scene2D-Part-2-Actions.aspx