【发布时间】:2012-06-30 10:48:31
【问题描述】:
我已经为 2 张图片使用了纹理绘制,但是背景图片变黑了。源图片是 png 并且它是透明的。我该如何解决这个问题?
如何渲染出具有透明度的原始图像?
【问题讨论】:
我已经为 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.begin() 之前使用此行Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 清除屏幕,以查看instructions here 的alpha 效果
如果您之前禁用过spritebatch.enableBlending(),请尝试。不过应该默认启用。
【讨论】: