libgdx纹理图像透明渲染

SeI*_*Ika 7 android libgdx

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

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

Nol*_*esh 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();
Run Code Online (Sandbox Code Playgroud)

  • 当然,你需要这样做.我刚刚展示了代码中最重要的部分. (3认同)

Dom*_*her 2

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