Pygame,尝试旋转精灵

Pygame, trying to rotate sprite

我正在尝试为用 pygame

编写的游戏旋转精灵

我没有收到任何控制台错误,但我的 sprite 保持完全相同并且不旋转 :(

有什么想法吗?

perso.image = pygame.image.load("sprites/[shadow]main_char_sprite.png").convert_alpha()
perso.image = pygame.transform.scale(perso.image, (53,60))
perso.rect = perso.image.get_rect()
perso.rect.x = 200
perso.rect.y = 200
perso.add(perso_group)

while 1:
    screen.fill(white)
    pygame.transform.rotate(perso.image,30) ########not working :(





    all_group.add(statique_group, zombie_group, perso_group)
    all_group.draw(screen)


    pygame.display.flip()

转换函数的 documentation 表示:

All these functions take a Surface to operate on and return a new Surface with the results.

所以需要将rotate的return值赋值给变量:

perso.image = pygame.transform.rotate(perso.image,30)

但是,文档还说:

Some of the transforms are considered destructive. These means every time they are performed they lose pixel data. Common examples of this are resizing and rotating. For this reason, it is better to retransform the original surface than to keep transforming an image multiple times.

所以你可能想保留原来的,并继续增加旋转角度。