Search code examples
androidlibgdx

Libgdx - SpriteBatch alpha not working


game.batch.setColor(1,1,1,alpha)

I am extending Game and implementing Screen. So the game class is the class passed to the Game screen. Then in Game Screen when you hit the wall I am doing this:

alpha -= delta;
if (alpha <= 0) {
     alpha = 0;
}
game.batch.setColor(1, 1, 1, alpha);
if (alpha == 0) {
     restartGame();
}

It works normally if I manually change transperency for each sprite. But it seems like the .setColor does not even work for SpriteBatch.


Solution

  • When you call sprite.draw(batch), it ignores whatever color the batch is set to and uses the color of the Sprite. If you want to fade every one of your sprites, you must change the alpha of every one of your sprites.