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 ?
Asked
Active
Viewed 97 times
1
-
self.player.rotation? – Joran Beasley Jan 15 '22 at 00:50
-
1If you rotate the same image multiple times it will lose quality. It's recommended to keep an unrotated copy and rotate that to a rotation value when needed. – Starbuck5 Jan 15 '22 at 03:18
1 Answers
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