剪辑或遮罩 2D 纹理

发布于 2024-07-26 06:57:02 字数 483 浏览 5 评论 0原文

嘿,我想知道是否有人知道如何为 GUI 或类似菜单的系统使用 2D 纹理进行裁剪。

这是我想要生成的示例输出

有一个尺寸为 500 x 500 的游戏屏幕。 其后面有一个尺寸为 1000 x 1000 的屏幕。

当我在 0, 0 处绘制纹理且父屏幕为 500 x 500 时,我希望不显示该组件

,但如果我在 500, 450 处绘制该组件并且纹理宽度和高度为 100,我希望只能看到组件的整个宽度,但只能看到组件高度的一半。

我想知道是否有一种简单的方法可以做到这一点?

编辑:

基本上我在想 Photoshop 中的蒙版效果之类的东西。

这是一张图片 剪切图片

黑色轮廓是纹理另一半的位置被画下来。

Hey i was wondering if anyone knows to do clipping with 2D textures for a gui or menu like system.

Heres an example output i would like to produce

Have a game screen with a size of 500 x 500.
With a screen behind it with a size of 1000 x 1000.

When i draw a Texture at 0, 0 with the parent screen of 500 x 500 i would like the component not to be shown

but if i draw the component at 500, 450 and the texture width and height are 100 i would expect to only see the whole width but only half the height of the component.

I was wondering if there is an easy way about doing this?

Edit:

Basically i was thinking something like a mask effect in Photoshop.

here is a picture Clipping picture

The black outline is where the other half of the texture would be drawn.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别再吹冷风 2024-08-02 06:57:02

您可以剪辑纹理。 当生成的形状是多边形时,
您可以通过简单地修改顶点和纹理坐标来做到这一点。

当剪切的纹理是复杂的形状时,事情就会变得更加棘手。

您还可以通过按正确的顺序绘制所有内容来进行剪辑。
它可能效率不高,但很容易。

ps 一张图片会有所帮助。

You can clip a texture. When the resulting shape is polygonal,
you can do it by simply modifying the vertices and texture coordinates.

When the clipped texture is a complicated shape, then things get trickier.

You can also clip by just drawing everything in the right order.
It may not be efficient, but it is easy.

p.s. A picture would help here.

少年亿悲伤 2024-08-02 06:57:02

解决这个问题的另一种方法:

基本上你有两个场景要绘制:游戏屏幕(图片)和背景屏幕(图片的红色部分)。

我认为您可以在两个不同的位图对象(或图形库中的任何类似对象)中绘制游戏屏幕和背景屏幕。

下一步是将整个背景屏幕位图剪辑到输出位图对象,然后您可以仅剪辑游戏屏幕的中心部分(以输出屏幕为中心的 500 x 500 正方形)。


PS:如果您可以添加有关您正在使用的图形库的更多详细信息,也许会更好。

Another way to solve this problem:

Basically you have two scenes to draw: the game screen (the blue part in your picture) and the background screen (red part of your picture).

I think that you could draw the game screen and the backgrond screen in two different bitmap objects (or whatever similar you have in your graphics library).

The next step is to clip the entire background screen bitmap to the output bitmap object and then you could clip just the central part (a 500 x 500 square centered in the output screen) of the game screen.


P.S: Maybe it would be better if you could add more details about the graphics library you are using.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文