Reputation: 67
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.
Upvotes: 0
Views: 108
Reputation: 211176
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.
Upvotes: 1