我已经使用纹理绘制来绘制2张图像,但是背景图片变成了黑色。源图片是png,它是透明的。我该如何解决?

如何用透明效果渲染原始图像?

最佳答案

试试这个:

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

10-07 21:03