How do I rotate an image around its center using Pygame?

后端 未结 6 1434
[愿得一人]
[愿得一人] 2020-11-22 00:13

I had been trying to rotate an image around its center in using pygame.transform.rotate() but it\'s not working. Specifically the part that hangs is rot_i

6条回答
  •  难免孤独
    2020-11-22 01:11

    I had to modify skrx solution as below, this way works for me.

    angle=0
    roll = true
    while roll:
        # clean surface with your background color
        gameDisplay.fill(color)
        self.image = yourImage
        rotate_image = pygame.transform.rotate(self.image, angle)
        rect = rotate_image.get_rect()
        pos = (((your_surface_width - rect.width)/2),((your_surface_height - rect.height)/2))
        gameDisplay.blit(rotate_image,pos)
        pygame.display.flip()
        angle+=2
        if angle == 360:
            roll=False 
    

提交回复
热议问题