Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparency Libgdx Android

We are programming a game in Android with libgdx. It's a Doodle Jump like.

At a point of the game, we want plateforms to disapear step by step by reducing the transparency of the picture. We've tested many things but nothing works.

batch.begin();
batch.draw(picture, posX, posY, width, heigth);
bach.end();

We also tried with this, but it doesn't work :

batch.setColor(1, 0, 0, 1);
like image 484
user3178291 Avatar asked May 19 '26 05:05

user3178291


1 Answers

SpriteBatch#setColor works: you didnt change the alpha (last value), thats why it didnt work for you.

batch.begin();
batch.setColor(1, 1, 1, 0.5F); //0.5F is the alpha value that you want (0-1)
batch.draw(picture, posX, posY, width, heigth);
batch.setColor(1, 1, 1, 1); //change it back to full opacity white, for the other objects to render correctly
bach.end();

If you start using Sprites, mrzli answer is the way to go.

like image 55
Lestat Avatar answered May 21 '26 19:05

Lestat