Search code examples
pythonpygamepolygondrawcollision

Is there a class in pygame to represent a non-AABB polygon?


I am making a game in python with pygame, and I am wondering if there is any class (with collisions) in pygame that supports non-AABB polygons. I know there is the pygame.draw.polygon function, but that takes a list of points instead of a rect like pygame.draw.rect.

Is there any way to do this in pygame?

If not, are there any pygame-compatible libraries that could do this?

If there are no libraries, how could I implement it?


Solution

  • The pygame.draw module does not generate objects. It just draws something on a Surface. You cannot use this for collision detection. I think you're confusing pygame.Rect and the pygame.draw module.
    The collision detection in pygame is based on rectangles or circles. See How do I detect collision in pygame?.
    Another option is to use pygame.mask.Mask objects, which you can use to detect overlapping shapes and sprites. See Pygame mask collision