简体   繁体   English

pygame,试图旋转精灵

[英]Pygame, trying to rotate sprite

I'm trying to rotate of sprite for my game written in pygame 我正在尝试为pygame编写的游戏旋转精灵

I don't get any consol error, but my sprite stay exactly the same and doesn't rotate :( 我没有收到任何consol错误,但是我的精灵仍然完全一样并且不会旋转:(

Any idea ? 任何想法 ?

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()

The documentation for the transform functions says: 转换函数的文档说:

All these functions take a Surface to operate on and return a new Surface with the results. 所有这些功能都需要使用Surface进行操作,并返回带有结果的新Surface。

So you need to assign the return value of rotate to the variable: 因此,您需要将rotate的返回值分配给变量:

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

However, the documentation also says: 但是,文档还说:

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. 因此,重新转换原始表面比保持多次转换图像更好。

So you may want to keep the original, and keep increasing the rotation angle instead. 因此,您可能希望保留原始图像,而继续增加旋转角度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM