繁体   English   中英

在libgdx中使用filledcircle和pixmap

[英]Using filledcircle and pixmap in libgdx

我正在使用Libgdx。 我想使用像素图在游戏中模拟雾,但是在生成"fogless""fogless"圆时遇到问题。 首先,我制作一个像素图,用黑色填充(一点点透明)。 填充后,我想在其上绘制一个实心圆,但是结果不是我所期望的。

this.pixmap = new Pixmap(640, 640, Format.LuminanceAlpha);
Pixmap.setBlending(Blending.None); // disable Blending
this.pixmap.setColor(0, 0, 0, 0.9f);
this.pixmap.fill();
//this.pixmap.setColor(0, 0, 0, 0);
this.pixmap.fillCircle(200, 200, 100);
this.pixmapTexture = new Texture(pixmap, Format.LuminanceAlpha, false);

在过程render()

public void render() {
  mapRenderer.render();
  batch.begin();
  batch.draw(pixmapTexture, 0, 0);
  batch.end();
}

如果我使用格式。 创建Pixmap和Texture时的Alpha,我都看不到更透明的圆圈。

这是我的问题:

在此处输入图片说明

问题

有人可以帮我吗? 我应该怎么做,在绘制一个完整的透明圆圈之前应该先初始化什么? 谢谢。

更新我已经找到我问题的答案。 我必须禁用混合以避免该问题。


现在我的代码:

FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, 620, 620, false);
Texture tex = EnemyOnRadar.assetManager.get("data/sugar.png", Texture.class);

batch.begin();
// others
batch.end();

fbo.begin();
batch.setColor(1,1,1,0.7f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw( tex, 100, 100);
batch.end();
fbo.end();

但是我看不到圆圈(这是png图像,代表透明的bg,白色填充的圆圈)。

我不确定这是否对您有用,但我只是分享一下:您可以使用FrameBuffer并执行以下操作:

  1. 在屏幕上绘制要绘制的所有内容。
  2. 结束您的SpriteBatch并开始您的FrameBuffer,再次开始SpriteBatch
  3. 绘制雾,它用黑色的非透明颜色填充整个“屏幕”(FrameBuffer)。
  4. 在要删除雾的位置,将“无雾”圆绘制为白色圆圈。
  5. FrameBuffer的alpha通道(透明度)设置为0.7或类似的值。
  6. 结束SpriteBatchFrameBuffer以将其绘制到屏幕上。

怎么了? 您绘制正常场景,没有雾。 您创建一个“虚拟屏幕”,用黑色填充,然后用白色圆圈覆盖黑色。 现在,您为该“虚拟屏幕”设置了透明胶片,并使用它覆盖了真实屏幕。 屏幕中位于白色圆圈下方的部分似乎很亮,而黑色的其余部分则使您的场景更暗。 读一些东西: 使用libgdx的2D火焰效果,与雾大致相同。 我的问题是: 没有box2d的Libgdx照明

编辑:另一个教程

让我知道是否有帮助!

编辑:某些伪代码:在创建中:

fbo = new FrameBuffer(Format.RGBA8888, width, height, false);

在渲染中:

fbo.begin();
glClearColor(0f, 0f, 0f, 1f);    // Set the clear color to black, non transparent
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);  // Clear the "virtual screen" with the clear color
spriteBatch.begin();  // Start the SpriteBatch
// Draw the filled circles somehow // Draw your Circle Texture as a white, not transparent Texture
spriteBatch.end(); // End the spritebatch
fbo.end(); // End the FrameBuffer
spriteBatch.begin();   // start the spriteBatch, which now draws to the real screen
// draw your textures, sprites, whatever
spriteBatch.setColor(1f, 1f, 1f, 0.7f); // Sets a global alpha to the SpriteBatch, maybe it applies alo to the stuff you have allready drawn. If so just call spriteBatch.end() before and than spriteBatch.begin() again.
spriteBatch.draw(fbo, 0, 0);  // draws the FBO to the screen.
spriteBatch.end();

告诉我是否有效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM