0
\$\begingroup\$

Now, suppose I always want to draw a circle at the center of a rect object, now, the problem is:

For example, if I do

pygame.draw.circle(Surface, BLUE, Surface.rect.center, radius, width=3)

This will and does fail because Surface.rect.center is actually the coordinates of the center of the Rect object relative to the (0,0) point -top left corner- of the display screen, not relative to the (0,0) point of the Rect object. However, the draw() function works relative to the Surface coordinate axis.

As far as here, those are my knowledge and I just think so, might be wrong in some aspects, if so, please let me know.

So, I can solve this simply by replacing Surface.rect.center, with:

(Surface.rect.width // 2, Surface.rect.height // 2)

However, I wonder, is there a way to get that center coordinate of the Rect object relative to its (0,0) point(origin) ?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Looking at the pygame docs on the Rect class, there doesn't seem to be any specific to obtain what you're looking for, but it's easy enough to calculate the way you did.

Is there any reason you want to avoid using (Surface.rect.width // 2, Surface.rect.height // 2)? If not, I'd say it's the best option.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .