我如何制作一个一个者的面具?

发布于 2025-02-11 00:22:51 字数 125 浏览 2 评论 0原文

我可以做一个直接的面具,如果是的话,如何?我正在试图在面具和矩形之间发生碰撞,并且由于我无法做一个面具(那时没有像素的完美碰撞),所以我想我会问我是否可以做一个一个emect的口罩?像鉴于尺寸和x/y的矩阵一样,我该如何基于此制作面具?

Can I make a mask of a rect, if so, how? I'm trying to make collisions between a mask and a rect, and since I can't make a rect of a mask(No pixel perfect collision then) I figured I'd ask if I could make a mask of a rect? Like given the dimensions and x/y positon of a rect, how could I make a mask based on that?

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

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

发布评论

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

评论(2

洋洋洒洒 2025-02-18 00:22:51

创建 pygame.mask.mask.mask.mask.mask.mask 对象并将所有位设置为 <<<代码> fill()

rect_mask = pygame.mask.Mask((rect.width, rect.height)))
rect_mask.fill()

使用 pygame.mask.mask.mask.overlap 用于掩模对象之间的碰撞检测。方法重叠()的偏移参数是 elethmask pygame.mask.mask.mask.mask.mask.mask object。

例如:

对象1:x1y1mask1
对象2:x2y2mask2

offset = (x2 - x1, y2 - y1)
if mask1.overlap(mask2, offset):
    print("hit")    

另请参阅 pygame与蒙版碰撞

Create a pygame.mask.Mask object and set all bits 1 with fill()

rect_mask = pygame.mask.Mask((rect.width, rect.height)))
rect_mask.fill()

Use pygame.mask.Mask.overlap to for the collision detection between Mask objects. The offset parameter of the method overlap() is the relative position of the othermask in relation to the pygame.mask.Mask object.

e.g.:

object 1: x1, y1, mask1
object 2: x2, y2, mask2

offset = (x2 - x1, y2 - y1)
if mask1.overlap(mask2, offset):
    print("hit")    

See also PyGame collision with masks and Pygame mask collision.

中二柚 2025-02-18 00:22:51

您可以使用width高度 的高度

playermask = pygame.mask.Mask((player.width, player.height))
playermask.fill()

you can create a pygame.mask.Mask using the width and height of the rect object:

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