2012-06-30 65 views
6

我已经使用纹理绘制2张图片,但背景图片变成黑色。源图片是一个PNG,它是透明的。我如何解决这个问题?libgdx纹理图像透明渲染

如何渲染出具有透明度的原始图像?

回答

1

尝试spritebatch.enableBlending()如果您之前已禁用它。但应该默认启用。

29

尝试这种情况:

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

我需要与该行'Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)第一清屏;''之前spriteBatch.begin()'看每阿尔法效果[说明](https://github.com/libgdx/libgdx/wiki/Spritebatch,-Textureregions,---Sprites) – rockhammer

+1

当然,你需要这样做。我刚才展示了代码中最重要的部分。 – Nolesh