Search code examples
androidlibgdx

Animate adding actor in libgdx


I have a TextButton that I would like to animate with addAction() when displaying it on the screen or removing it..The button is added automatically when another button is clicked on the screen

Line below simply doesn't work:

    TextButton sound_icon;
    Stage stage;
    .....

//stage.addActor(sound_icon) This one works but no animation
stage.addAction(Actions.addAction(Actions.fadeIn(0),sound_icon));

Solution

  • You have to add the actor to the stage like you do in the commented code:

    stage.addActor(sound_icon);
    

    To get your animation working, you have to initialize your actor with an alpha of zero:

    sound_icon.setColor(1f, 1f, 1f, 0f);
    

    Now, you add the fade action:

    sound_icon.addAction(Actions.fadeIn(1f));