pygame.Rect around circle

Question:

I’m trying to make a pong game in pygame , but i can’t figure out how to but a ball circle , which i can create with pygame.draw.circle into a pygame.Rect object so i can use the colliderect function and manipulate the ball’s position.
For example, with rectangles, i can do something like this :

rect = pygame.Rect(255, 255, 100, 100)
pygame.draw.rect(screen, yellow, rect)

and then when i change the pygame.Rect object position , the drawing primitives position also changes. How can the same effect be achieved when i want to draw a circle, instead of a rectangle?
Thank you.

Asked By: stensootla

||

Answers:

http://pygame.org/docs/ref/draw.html#pygame.draw.circle

pygame.draw.circle

Draw a circle around a point

pygame.draw.circle(Surface, color, pos, radius, width=0): return Rect

If you do:

circleRect = pygame.draw.circle(windowSurface, (0,0,0), (10, 10), 5)

Pygame will give you the rectangle that the circle is in, and you can manipulate it.

I hope that helped, and best of luck to you.

Answered By: Da-Jin

something really cool-
pygame.draw.rect(screen, "red", pygame.Rect(100, 100, 100, 100),100, 100)
This draws a circle (NO CAP)

Answered By: Dishanth
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.