我检查碰撞:
offset = (x0 - x1, y0 - y1)
result = player1.mask.overlap(player2, offset)
它在两个图像之间工作。
但如果我想检查图像和pygame.draw.line(...)
(I use it https://stackoverflow.com/questions/42317756/how-to-get-the-surface-from-a-rect-line/42318036#42318036用于从线创建蒙版)。mask.overlap
回报None
:
surface = self.gameDisplay.subsurface(pygame.draw.line(self.gameDisplay, colors.GREEN, [100, 100], [200, 200], 5))
line_mask = pygame.mask.from_surface(surface)
pygame.draw.line(self.gameDisplay, colors.GREEN, [100, 100], [200, 200], 5)
offset = (x0 - x1, y0 - y1)
result = player1.mask.overlap(mask, offset)
对不起我的英语不好。