0
\$\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\$
0
\$\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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.