Ask coding questions

← Back to all posts
Pygame rotation size change
DavidPC123 (2)

I am trying to rotate an image so it is facing the mouse at all times and I am noticing that the image size is changing. I am trying to troubleshoot but am having no luck. I would love some advice.

Here is what I am using:

ang = 360 - math.atan2(mousey - 540, mousex - 960) * 180 / math.pi
rotcircle = pygame.transform.scale(pygame.transform.rotate(redcircle,ang), [100, 100])
rect = rotcircle.get_rect(center=(960,540))
screen.blit(rotcircle,rect)

Comments
hotnewtop
malvoliothegood (851)

Have you a repl that I can look at? I know when using JavaScript and an HTML canvas I had to take into account that an image's reference point, in terms of the drawing context, was its top left corner. I had to move the drawing context to its centre, do the rotation then move the context back to the top left corner. Do images behave the same when using pygame?

DavidPC123 (2)

@malvoliothegood I also posted this question on stackoverflow and got a good answer.