简体   繁体   English

pygame 复制图像,然后旋转它

[英]pygame copy image, then rotate it

I have one picture which I want to use multiple times on the screen but it always has to be rotated differently.我有一张我想在屏幕上多次使用的图片,但它总是必须以不同的方式旋转。 If I use the pygame.image.rotate function it rotates the imported image so I can't rotate every image on its own.如果我使用 pygame.image.rotate function 它会旋转导入的图像,因此我无法单独旋转每个图像。 Is there any way I can copy it in the code and then rotate it?有什么办法可以在代码中复制它然后旋转它?

> image = pygame.image.load("assets/image")  
pygame.transform.rotate(image, 20) #rotated by 20 deg  
pygame.transform.rotate(image, 20) #rotated by 20  + 20 deg  
#what i want  
copy(pygame.transform.rotate(image, 20))

If you use pygame.image.load() and put it in a variable, then just put again in another one如果您使用pygame.image.load()并将其放入变量中,然后再次放入另一个变量中
For example:例如:

image = pygame.image.load(path) #if you load like that
image_2 = pygame.image.load(path)
image = pygame.transform.rotozoom(image,90,1) #image 2 stays the same and you can rotate it a different way

The function pygame.image.rotate does not exist, however pygame.transform.rotate does exist. function pygame.image.rotate不存在,但pygame.transform.rotate确实存在。

pygame.transform.rotate does not rotate the image itself. pygame.transform.rotate不会旋转图像本身。 This function creates a rotated copy of the image and returns the copy:此 function 创建图像的旋转副本并返回副本:

image = pygame.image.load("assets/image") 
rotated_image_copy = pygame.transform.rotate(image, 20) 

See also How do I rotate an image around its center using PyGame?另请参阅如何使用 PyGame 围绕其中心旋转图像? . .

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

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