libgdx纹理图像透明渲染

时间:2012-06-30 10:48:31

标签: android libgdx

我使用纹理绘制2幅图像,但背景图片变黑。源图片是png,它是透明的。我该如何解决这个问题?

如何以透明度渲染原始图像?

2 个答案:

答案 0 :(得分:30)

试试这个:

            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();

答案 1 :(得分:2)

如果您之前已将其停用,请尝试spritebatch.enableBlending()。默认情况下应该启用。