fadeIn, fadeOut and moveTo actions don't work on Actors

2.3k Views Asked by At

I have a stack which I'm filling with tables . I'm trying to fadeIn, fadeOut, moveTo, several of these actors but the addAction methods don't work:

    stack_stage = new Stack();      
    table_menu = new Table();
    level_selector = new ex01MenuLevelSelectorBase(skin, table_menu);       

    table_menu.add(level_selector).center();
    table_menu.setFillParent(true);

    stack_stage.setFillParent(true);
    stack_stage.add(table_menu);
    stage.addActor(stack_stage);

    table_level_selector = new Table();
    image_level_selector = new Image(skin.getDrawable("hud-level5"));
    image_level_selector.setColor(1f, 1f, 1f, 0.5f);
    table_level_selector.add(image_level_selector);     

    stack_stage.addActor(table_level_selector);

    //doesn't work 
    table_level_selector.addAction(com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeOut(5f));

    //works
    table_level_selector.addAction(com.badlogic.gdx.scenes.scene2d.actions.Actions.hide());
2

There are 2 best solutions below

8
On BEST ANSWER

try this

table_level_selector.addAction(Actions.sequence(Actions.fadeOut(5f),Actions.hide ()));  

or

table_level_selector.addAction(Actions.sequence(
                              com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeOut(5f),
                              com.badlogic.gdx.scenes.scene2d.actions.Actions.hide ()));

is likely that this is your mistake, try this in the render method

stage.act(Gdx.graphics.getDeltaTime());
0
On

I know it's a bit late, but today I encountered the same and problem and realized that I hadn't added

Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

in the render method. This caused my image to draw over itself:

  1. When it faded in it took less than I expected (because the alphas were adding)

  2. When it faded out the image didn't change (because there was the same image underneath)

I know this isn't your case, but this error took me some time to figure out what wasn't working just to discover this little oversight!