LibGdx - Transition between Screens

前端 未结 4 919
孤城傲影
孤城傲影 2021-02-04 03:50

I\'m trying to change the animation between Libgdx Screens. I want to write my custom animation (fade in, fade out, etc). Can someone give me a clue? I can\'t seem to find the i

4条回答
  •  深忆病人
    2021-02-04 04:21

    Here is what i do:

    FadeIn is pretty simple, just add this to your fadein Screens show():

    stage.getRoot().getColor().a = 0;
    stage.getRoot().addAction(fadeIn(0.5f));
    

    FadeOut is a little trickier. You dont want to switch screens immediately, so instead of calling game.setScreen(newScreen) create a method in your fadeout Screen like this:

    public void switchScreen(final Game game, final Screen newScreen){
        stage.getRoot().getColor().a = 1;
        SequenceAction sequenceAction = new SequenceAction();
        sequenceAction.addAction(fadeOut(0.5f));
        sequenceAction.addAction(run(new Runnable() {
            @Override
            public void run() {
                game.setScreen(newScreen);
            }
        }));
        stage.getRoot().addAction(sequenceAction);
    }
    

    Like this, you delay the screen switching for the duration of the fade out.

提交回复
热议问题