Libgdx 创建一个pixmap,它是两个形状的差异

Libgdx 创建一个pixmap,它是两个形状的差异,libgdx,Libgdx,我想在我的libGDX游戏中创建一个覆盖层,以便在登录时使用。基本上,我想在整个屏幕上覆盖一个40%的alpha矩形(这很容易),但我想在感兴趣的区域顶部剪一个圆圈,用户应该集中注意力。有没有一种方法可以创建两种形状或像素贴图不同的纹理 Pixmap overlay = new Pixmap(screenWidth, screenHeight, Pixmap.Format.RGBA8888); overlay.setColor(0, 0, 0, 0.4f); overlay.fillRectan

我想在我的libGDX游戏中创建一个覆盖层,以便在登录时使用。基本上,我想在整个屏幕上覆盖一个40%的alpha矩形(这很容易),但我想在感兴趣的区域顶部剪一个圆圈,用户应该集中注意力。有没有一种方法可以创建两种形状或像素贴图不同的纹理

Pixmap overlay = new Pixmap(screenWidth, screenHeight, Pixmap.Format.RGBA8888);
overlay.setColor(0, 0, 0, 0.4f);
overlay.fillRectangle(0, 0, screenWidth, screenHeight);

Pixmap overlayCutout = new Pixmap(screenWidth, screenHeight, Pixmap.Format.RGBA8888);
overlayCutout.setColor(Color.WHITE);
overlayCutout.fillCircle(focusAreaX, focusAreaY, radius);

Texture t = new Texture(overlay); 
//subtract overlayCutout??
overlay.dispose();
overlayCutout.dispose();

batch.draw(t);

我不确定我是否完全明白了你想要做的事情,但我认为诀窍是只使用一个
Pixmap

Pixmap overlay = new Pixmap(screenWidth, screenHeight, Pixmap.Format.RGBA8888);
overlay.setColor(0, 0, 0, 0.4f);
overlay.fillRectangle(0, 0, screenWidth, screenHeight);

// the trick is to "redraw" the inner circle with an "invisible" colour alpha=0
overlay.setBlending(Blending.None);
overlay.setColor(1, 1, 1, 0);
overlay.fillCircle(focusAreaX, focusAreaY, radius);
overlay.setBlending(Blending.SourceOver);

Texture t = new Texture(overlay); 
overlay.dispose();

batch.draw(t);

谢谢你的回复,@noone。不幸的是,我试过了,这个圆确实是看不见的——根本没有切口,只有一个实心的半透明矩形。@rundavidrun我编辑了我的答案。您必须将混合模式设置为“无”,这样它将不会混合,而是完全改变颜色。之后,您必须将其设置回默认值。