Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgdx texture image transparent render

Tags:

android

libgdx

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?

like image 460
SeIka Avatar asked Jun 30 '12 10:06

SeIka


2 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();
like image 130
Nolesh Avatar answered Oct 21 '22 04:10

Nolesh


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

like image 2
Dominik Bucher Avatar answered Oct 21 '22 04:10

Dominik Bucher