1
\$\begingroup\$

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):
        super().__init__()
        self.color = color
        self.image = pygame.Surface([width, height])
        self.image.fill(color)
        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
\$\endgroup\$
0

2 Answers 2

1
\$\begingroup\$

You have to take the returning value of rotate :

player.image = pygame.transform.rotate(player.image, 45)
\$\endgroup\$
0
\$\begingroup\$

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)
\$\endgroup\$
2
  • \$\begingroup\$ It's not clear to me what is fundamentally different than the other proposed answer. \$\endgroup\$
    – Vaillancourt
    Apr 29 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 at 18:59

You must log in to answer this question.

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