1
\$\begingroup\$

Howto apply alpha to a sprite so it will work.

With the following code, the sprite still is completely visible.

Can someone help me ?

batch.enableBlending();
if (sprite != null) {
    Color c = sprite.getColor();
        c.a = 0;
        sprite.setColor(c);
}
batch.draw(sprite, x, y);
sprite.setAlpha(0f);
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

You're drawing the sprite the wrong way:

Gdx.gl.glClearColor(0, 0, 0, 1); // Clear the screen with black
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Clear the screen

batch.enableBlending(); // Enable alpha
batch.begin();

sprite.setAlpha(0);
sprite.draw(batch); // This is how you should draw a sprite. 

batch.end();
batch.disableBlending();

This works fine for me.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .