gpt4 book ai didi

libgdx - 创建一个像素图,它是两个形状的差异

转载 作者:行者123 更新时间:2023-12-02 02:01:00 24 4
gpt4 key购买 nike

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

关于libgdx - 创建一个像素图,它是两个形状的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20015975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com