【问题标题】:libgdx texture image transparent renderlibgdx 纹理图像 透明渲染
【发布时间】:2012-06-30 10:48:31
【问题描述】:

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

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

【问题讨论】:

    标签: android libgdx


    【解决方案1】:

    试试这个:

                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 效果
    • 当然,你需要这样做。我只是展示了代码中最重要的部分。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 1970-01-01
      • 2013-10-07
      • 2014-10-28
      • 2011-11-24
      • 1970-01-01
      相关资源
      最近更新 更多