2012-06-30 67 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