2
\$\begingroup\$

How can I make transition between stages in libgdx ?

I have 2 screens MenuScreen and GameScreen each of which has a stage

I write the following to make a transition :

in MenuScreen

SequenceAction sequenceAction = new SequenceAction();
sequenceAction.addAction(Actions.moveTo(-Gdx.graphics.getWidth(), 0, 4.0f));
sequenceAction.addAction(Actions.run(new Runnable() {
     @Override
     public void run() {
        gameMain.setScreen(new GameScreen(gameMain));
             }
     }));
stage.getRoot().addAction(sequenceAction);

in GameScreen

stage.getRoot().setPosition(Gdx.graphics.getWidth(), 0);
stage.getRoot().addAction(Actions.moveTo(0, 0, 4.0f));

but the problem is GameScreen does not following MenuScreen directly i.e it wait until MenuScreen has completely gone from screen and I want them to move at the same time

\$\endgroup\$
1
  • \$\begingroup\$ Unfortunately due to the way screens work, only one can be rendered at a time. This means that it is not possible to briefly draw both at any single time. One solution would be to take a screenshot of one of the screens before the transition and pass it to the next screen so it can complete the effect. \$\endgroup\$ Commented Jul 17, 2016 at 14:36

1 Answer 1

1
\$\begingroup\$

There are a lot of different kinds of transition. To concretely answer this question clarify which kind of transition you are looking for.

If you want to do a blended transition, you'll need to render a single frame of the old scene to a buffer, render a single frame of the new scene to a buffer, and then do the transition animation. Here's a pointer for the FrameBuffer.

A simpler strategy is probably to just fade to black on the old scene, then fade in from black on the new scene.

\$\endgroup\$
3
  • \$\begingroup\$ as you said I want to fade out the current screen and fade in the next one How can I do this ? I see a class by someone which makes the transition between the current and next screen but I see this can't be applied as I can't render next screen without show method (it gives me NullPointerException) or I can make the transition by passing a screenshot of previous screen to next screen What do you think ? \$\endgroup\$
    – MAGS94
    Commented Jul 19, 2016 at 1:35
  • \$\begingroup\$ blog.gemserk.com/2012/03/05/… \$\endgroup\$ Commented Jul 19, 2016 at 17:21
  • \$\begingroup\$ badlogicgames.com/forum/viewtopic.php?f=11&t=11092 \$\endgroup\$ Commented Jul 19, 2016 at 17:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .