I want to elaborate on the bug I just posted because I just realized that offset values in the top and left fields actually messes up a lot of other things: right, bottom, bottomright, center, and all calculated fields are bugged: r = pygame.Rect(10,10,110,110)
120r.right
120r.bottom
r.center
(65, 65)
- Guillaume Rava
Hello,
It seems Rect.collidepoint(x,y) works fine as long as the Rect's top and left values are set to zero. When the Rect object is offset from zero, collidepoint returns 1 when (x,y) is outside of the Rect. Example:
>>> import pygame >>> r = pygame.Rect(10,10,110,110) >>> r.collidepoint(0,0) # GOOD 0 >>> r.collidepoint(10,10) # GOOD 1 >>> r.collidepoint(110,110) # BAD 1 >>> r.collidepoint(119,119) # BAD 1 >>> r.collidepoint(120,120) # GOOD 0
Sincerely, Guillaume Rava.