Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

When does rect1 colliderect in pygame return false?


Asked by Faye Espinoza on Dec 10, 2021 FAQ



If one Rect's bottom border is another Rect's top border (i.e., rect1.bottom=rect2.top), the two meet exactly on the screen but do not overlap, and rect1.colliderect(rect2)returns false. New in pygame 1.9.2: The Rect class can be subclassed.
Also Know,
The Pygame Rect already comes with a few collision detection functions that may just do what you need:
Keeping this in consideration, Rects can also be created from python objects that are already a Rect or have an attribute named "rect". Any pygame function that requires a Rect argument also accepts any of these values to construct a Rect.
In respect to this,
Most python containers can be searched for collisions against a single Rect. The area covered by a Rect does not include the right- and bottom-most edge of pixels. If one Rect's bottom border is another Rect's top border (i.e., rect1.bottom=rect2.top), the two meet exactly on the screen but do not overlap, and rect1.colliderect(rect2)returns false.
Just so,
Rects can also be created from python objects that are already a Rect or have an attribute named "rect". Any pygame function that requires a Rect argument also accepts any of these values to construct a Rect. This makes it easier to create Rects on the fly as arguments to functions.