Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to make a pong game in pygame, but I can't figure out how to put a ball circle, which I can create with pygame.draw.circle into a pygame.Rect object so i can use the colliderect function to manipulate the ball's position.

For example, a rectangle, I can do something like this:

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

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Presumably you're using a center position and a radius to draw the circle. Just create a rect like this:

crect = pygame.Rect(center[0]-radius, center[1]-radius, \
                    radius*2, radius*2)

Then draw the circle like this:

pygame.draw.circle(screen, yellow, crect.center, radius)
share|improve this answer
    
I can't believe i couldn't figure out something so simple .d Thank you very much for your help. –  geekkid Jun 2 '12 at 22:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.