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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With