Search code examples
androidlibgdx

LibGDX screen transition using stage


I am very new to this so please make it easy for me to understand. I have created a game with three different screens and now that I have finished the game I wanted to add fade in and out transitions between the screens. I am trying to use the stage.addAction to perform these effects however it does not produce any effect. I am not using any stage or actors for my game so I am only adding the stage for the sole purpose of the fading out effect.

There is no error on my app, however, it does nothing when the stage.addAction is called.

Here is the parts of my code relating to the stage.

private Stage stage;

show() stage = new Stage();

render() stage.draw

onTouchUp() stage.addAction(Actions.sequence(Actions.fadeOut(1), Actions.run(new Runnable() {
            @Override
            public void run() {
                game.setScreen(new gameScreen(game));
            }
        }

Solution

  • Your fade out method looks fine so it should be working. You should consider two following questions:

    • do you remembered about calling stage.act() in render? If not the actions won't be proceed
    • are you sure onTuchUp() in your case working fine? Try to add some System.out.println() into this method