Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGdx - Transition between Screens

Tags:

screen

libgdx

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 implementation of the transition in the Libgdx code.

like image 373
ruff1991 Avatar asked Jul 06 '12 12:07

ruff1991


3 Answers

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.

like image 160
Kedu Avatar answered Nov 07 '22 15:11

Kedu


I've implemented some sliding transitions using Scene2D and the universal tween engine. You can find example code here.

http://www.netthreads.co.uk/2012/02/09/libgdx-scene2d-demo-with-scene-transitions/

Update: This article illustrates the approach I took to implement sliding transitions. There is a link at the bottom which takes you to a set of demos here https://github.com/alistairrutherford/libgdx-demos

There are clear instructions on how to build the demos but you will need to have at least a basic grasp of maven and how to set it up.

like image 3
alrutherford Avatar answered Nov 07 '22 14:11

alrutherford


I've implemented similar methods. Thanks to Gustavo Steigert, I learned a lot from his blog here's where you could find his example with the sequence of fadeIn and fadeOut.

http://steigert.blogspot.in/2012/02/3-libgdx-tutorial-scene2d.html

You can follow through his blog completely to have a better idea of the flow of things and find the tags for the post's source code in the end of each if his posts.

like image 3
alex Avatar answered Nov 07 '22 16:11

alex