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\$
  • \$\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\$ – BleedObsidian Jul 17 '16 at 14:36
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.

| improve this answer | |
\$\endgroup\$
  • \$\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 Jul 19 '16 at 1:35
  • \$\begingroup\$ blog.gemserk.com/2012/03/05/… \$\endgroup\$ – Will Iverson Jul 19 '16 at 17:21
  • \$\begingroup\$ badlogicgames.com/forum/viewtopic.php?f=11&t=11092 \$\endgroup\$ – Will Iverson Jul 19 '16 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.