libgdx 纹理图像透明渲染



我已经对 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();

如果您之前禁用过它,请尝试spritebatch.enableBlending()。不过应该默认启用。

最新更新