Home » Android » android – libgdx texture image transparent render

android – libgdx texture image transparent render

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have used texture draw for 2 images, but the background picture becomes black. The source picture is a png and it’s transparent. How do i solve this?

How do I render out the original image with transparency?

How to&Answers:

Try this:

            spriteBatch.begin();
            //background
            seaTexture = new Texture(px);
            Color c = spriteBatch.getColor();
            spriteBatch.setColor(c.r, c.g, c.b, 1f); //set alpha to 1
            spriteBatch.draw(seaTexture, 0, 0, 480, 320);
            //foreground
            c = spriteBatch.getColor();
            spriteBatch.setColor(c.r, c.g, c.b, .3f);//set alpha to 0.3
            spriteBatch.draw(blockTexture, 50, 100, 120, 120);

            spriteBatch.end();

Answer:

Try spritebatch.enableBlending() if you have disabled it before. Should be enabled by default though.