0

I can load an image into pygame and blit it to the display. I can then create a mask from this to use for collisions. However, though the mask moves with the sprite, it is not lined up, for any given sprite image there is a different offset. I want to know how to remove this.

image = pygame.image.load("test_rect.png")
mask = pygame.mask.from_surface(image)
DISPLAY.blit(image, (DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2))
if mask.overlap_area(player.mask, ((DISPLAY_WIDTH/2 - player.x_position), (DISPLAY_HEIGHT/2 - player.y_position))) != 0:
        player.shove(0, -500) #this just tells me that it has collided

with a 120x120 shape for the image, there is a very distinct gap between where the object appears to be and where it can be collided with. It can be fixed by manually applying an offset to the collision but has to be worked out for every image I may want to use.

0 Answers0