我使用纹理绘制了两张图片,但背景图片变成了黑色。源图片是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()
。不过默认情况下应该是启用的。
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
清除屏幕,然后才能在spriteBatch.begin()
前看到透明效果,具体请参考这里的说明。 - rockhammer