pygame  
PyGame
Documentation
||  Home  ||  Help Contents  ||
 
|| CD || Channel || Font || Joystick || Rect || Sound || Surface ||
|| pygame || cdrom || constants || display || event || font || image ||
|| joystick || key || mixer || mixer_music || mouse || surfarray || time ||

Rect

The rectangle object is a useful object representing a rectangle area. Rectangles are created from the pygame.rect() function. This routine is also in the locals module, so importing the locals into your namespace allows you to just use rect().
 
Rect contains helpful methods, as well as a list of modifiable members: top, bottom, left, right, topleft, topright, bottomleft, bottomright, size, width, height, center, centerx, centery. When changing these members, the rectangle will be moved to the given assignment. (except when changing the size, width, or height member, which will resize the rectangle around the center).
 
The rectstyle arguments used frequently with the Rect object (and elsewhere in PyGame) is one of the following things. First, an actual Rect object. Second, a sequence of [xpos, ypos, width, height]. Lastly, a pair of sequences, representing the position and size [[xpos, ypos], [width, height]]. Also, if a method takes a rectstyle argument as its only argument, you can simply pass four arguments representing xpos, ypos, width, height.
clamp - move rectangle inside another
clip - rectangle cropped inside another
collidepoint - point inside rectangle
colliderect - check overlapping rectangles
colliderect - find overlapping rectangle
colliderectall - find all overlapping rectangles
contains - check if rectangle fully inside another
inflate - new rectangle with size changed
move - new rectangle with position changed
normalize - corrects negative sizes
union - rectangle covering both input

clamp
Rect.clamp(rectstyle) -> Rect
 
clip
Rect.clip(rectstyle) -> Rect
 
collidepoint
Rect.collidepoint(x, y) -> bool
 
colliderect
Rect.colliderect(rectstyle) -> bool
 
colliderect
Rect.colliderect(rectstyle list) -> int index
 
colliderectall
Rect.colliderectall(rectstyle list) -> int index
 
contains
Rect.contains(rectstyle) -> bool
 
inflate
Rect.inflate(x, y) -> Rect
 
move
Rect.move(x, y) -> Rect
 
normalize
Rect.normalize() -> None
 
union
Rect.union(rectstyle) -> Rect