Pygame Rect, what are the arguments?

14,748

Both of them work:

class pygame.Rect
    pygame object for storing rectangular coordinates
    Rect(left, top, width, height) -> Rect
    Rect((left, top), (width, height)) -> Rect
    Rect(object) -> Rect

So, if you have coordinates (x1, y1) and (x2, y2), both of the following would work:

pygame.Rect(x1, y1, x2-x1, y2-y1)
pygame.Rect((x1, y1), (x2-x1, y2-y1))
Share:
14,748
Andrew Lalis
Author by

Andrew Lalis

I'm in the process of learning python!

Updated on June 23, 2022

Comments

  • Andrew Lalis
    Andrew Lalis almost 2 years

    I know this may sound stupid, but the pygame documentation on their website says that it is:

    x = pygame.Rect(left,top,width,height)
    

    However, in my program, I cannot figure out if that is true, or if the arguments are actually two sets of coordinates. I'm not nearly experienced to find out by looking through the pygame source code.

  • Andrew Lalis
    Andrew Lalis over 9 years
    but could I also put Rect(x1,y1,x2,y2)? as in two sets of coordinates
  • tckmn
    tckmn over 9 years
    @AndrewLalis No, it would be Rect(x1, y1, x2-x1, y2-y1). The second pair of arguments is the width and the height.