I am making a game in Pygame and I want it so every time the sprite jumps it rotates mid-air and lands on its side. A lot like Geometry Dash jumping if you have ever played that. I have some code but it won't rotate.

This is my player class

class Player(pygame.sprite.Sprite):
    def __init__(self, color, x, y, width, height):
        self.color = color
        self.image = pygame.Surface([width, height])
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

and this is my code to rotate

while running:
    if keys[pygame.K_SPACE]:
            pygame.transform.rotate(player.image, 45)
            isjump = True    
            v = jump_v

2 Answers 2


You have to take the returning value of rotate :

player.image = pygame.transform.rotate(player.image, 45)

Pygame.transform.rotate doesn't directly affect the image, instead it makes a copy of it so do

player.image = pygame.transform.rotate(player.image,45)
  • \$\begingroup\$ It's not clear to me what is fundamentally different than the other proposed answer. \$\endgroup\$
    – Vaillancourt
    Apr 29, 2022 at 18:54
  • \$\begingroup\$ Please keep in mind that generally, posting short answers means that those answers are not of super high quality, and that posting a lot of those could impact your use of the site. \$\endgroup\$
    – Vaillancourt
    Apr 29, 2022 at 18:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .