I've been trying to create a white-screen fade effect for my libgdx game.
When I run the following code with fadeOut = false
, nothing happens (white-screen does not appear because alpha is 0). When fadeOut = true
, it works (fades out) until the actors alpha is down to 0.5f
, then it rebounds and starts fading in. No clue why.
if(fadeOut){
map.setColor(new Color(1, 1, 1, 1));
addAction(Actions.fadeOut(duration));
}else{
map.setColor(new Color(1, 1, 1, 0));
addAction(Actions.fadeIn(duration));
}
When I run the exact same code but switch the starting alpha's like this:
if(fadeOut){
map.setColor(new Color(1, 1, 1, 0)); //notice this is 0 now
addAction(Actions.fadeOut(duration));
}else{
map.setColor(new Color(1, 1, 1, 1)); // notice this is 1 now
addAction(Actions.fadeIn(duration));
}
When I run this code with fadeOut = false
, nothing happens (screen is all white though, because starting alpha is 1). When fadeOut = true
, it actually fades in. sigh...
Here's the draw method i'm running, but I doubt there's an issue there.
@Override
public void draw(Batch batch, float parentAlpha){
batch.draw(texture, 0, 0);
//Get the current color of the actor
batch.setColor(getColor());
act(Gdx.graphics.getDeltaTime());
}
I really don't know why this is happening, any insight would be valuable.
Thanks!
Edit: Here's the full code I'm using to call the fades:
I have a "StartScreen" object that gets initialized (and contains the stage), and this piece of code is in it's constructor:
fade = new Fade((int)GdxGame.getWidth(), (int)GdxGame.getWidth(), Color.WHITE, fadeOut, duration);
stage.addActor(fade);
In the same StartScreen class, I have the following code to draw the stage:
@Override
public void render() {
super.render();
stage.draw();
}//end render
The following code then calls the "Fade" objects constructor which has the code mentioned above:
public Fade(int width, int height, Color color, boolean fadeOut, float duration){
this.fadeIn = fadeOut;
this.duration = duration;
Pixmap map = new Pixmap(width, height, Pixmap.Format.RGBA8888);
if(fadeOut){
map.setColor(new Color(1, 1, 1, 1));
addAction(Actions.fadeOut(duration));
}else{
map.setColor(new Color(1, 1, 1, 0));
addAction(Actions.fadeIn(duration));
}
map.fillRectangle(0, 0, width, height);
texture = new Texture(map);
map.dispose();
}
Update: Changing the alpha with this line:
map.setColor(new Color(1, 1, 1, alpha));
to 0.2f
or 0.7f
works fine. Though that's because it's changing the alpha of the pixmap (and later becomes the texture)- which leads me into investigation of whether fadeOut or fadeIn
change the texture's alpha or something else...