Like jimmt said, Actions.fadeIn is a nice way to use fades for actors or a stage (actually, actions are nice for lot’s of things).
If you don’t use actors, you can still benefit from the actions system, as an Actor is not an abstract class. Create an actor and assign it the initial color value and add a fade in action. Call act on the actor in your update/render method. This will step the actions you have put in. Then you can get the actors color and have the updated color. You can just use the alpha component of the color. Here is some example code of how you could use it:
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
public class FadeTest {
//Transparent color
private static final Color TRANSPARENT = new Color(1f, 1f, 1f, 0f);
private Actor fadeActor = new Actor();
private SpriteBatch batch = new SpriteBatch();
//Your init method
public void create() {
//Assign the starting value
fadeActor.setColor(TRANSPARENT);
// Fade in during 2 seconds
fadeActor.addAction(Actions.fadeIn(2f));
}
//Your update and render method
public void draw() {
//Act updates the actions of an actor
fadeActor.act(Gdx.graphics.getDeltaTime());
//Get the current color of the actor
batch.setColor(fadeActor.getColor());
batch.begin();
//Render stuff
batch.end();
}
}
It probably might be a bit overkill, but I like it because the actions enable you to easily do different transitions (even in parallel). So if you don’t know actors and actions, have a look at it.