创建一个像素图,这是两个形状的差异

时间:2013-11-16 07:28:32

标签: libgdx

我想在我的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);

1 个答案:

答案 0 :(得分:3)

我不确定我是否完全得到了你想做的事,但我认为诀窍是只使用一个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);