How to rotate an image around its center while its scale is getting larger(in Pygame)

后端 未结 2 748
灰色年华
灰色年华 2021-01-22 10:33

I loaded an image and I want it to rotate around its center, while its scale is getting larger. I know how to rotate an image around its center originally, but it\'s hard for me

2条回答
  •  抹茶落季
    2021-01-22 11:02

    You need to re-set the image's centre after it is scaled (& rotated) as both of these can change the image size.

    # rotate and zoom the sprite
    self.image = pygame.transform.rotozoom(self.original_image, self.angle, self.scale)
    # reset it back to original centre
    self.rect = self.image.get_rect(center=self.rect.center)
    

    Another thing to consider is to ensure your image-content is centred within itself. (Imagine a rectangle with only content drawn to one-side) the rotation will be centred geometrically, but still look weird visually as it rotates.

提交回复
热议问题