1

I have a little problem with pygame. I am actually coding a project with pygame and I would like to know how could I know the angle of a sprite because pygame.transfrom.rotate(self.player.image, 50) is rotating it for 50 degrees from the angle that it is at actually, but i would like to rotate it from zero. so I thought I could just substract the angle of the sprite to itself to make it zero but I cant find how to find the angle of the sprite. Could someone help me please ?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Akopa
  • 53
  • 8

1 Answers1

3

You cannot get the angle from an image (pygame.Surface). A Surface is always rectangular. pygame.transform.rotate creates a new but slightly larger surface. The size of the new Surface is the size of the rotated rectangle's axi-aligned bounding box. If you want to know how the image was rotated, you need to store the angle in an attribute.

Anyway, never rotate an image that has already been rotated. This leads to weird distortions. See How do I rotate an image around its center using PyGame?.

Store the original image in an attribute. e.g.:

class MySprite(pygame.sprite.Sprite):
    def __init__(self, x, y, image):
        super().__init__() 
        self.original_image = image
        self.image = self.original_image
        self.rect = self.image.get_tect(center = (x, y))
        self.angle = 0

    def roatate(self, angle):
        self.angle = angle
        self.image = pygame.transfrom.rotate(self.original_image, slef.angle)
        self.rect = self.image.get_tect(center = (x, y))

    def resetRotate(self):
        self.rotate(0)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174