0

Can anyone tell me the use of Pygame.Rect. I am creating a simple program to draw and display rectangle in screen and check for collision with screen. I saw a video on youtube where the Youtuber uses the following code:

moving_rect=pygame.Rect(300,300,100,100)

Now I don't know what is Pygame.Rect is used for and what the above line of code actually does.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

1

A pygame.Rec describes a rectangular area. It can be use to define the bounding box of an object. This can be useful for a collision test. See How do I detect collision in pygame?.

Actually it is used to define the location of a pygame.sprite.Sprite object.
Notice that a pygame.Surface object has no position. It only contains the pixel information. However, a Rect and a Surface together define the position of an image (Sprite) in the window.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174