pygame 复制图像,然后旋转它

pygame copy image, then rotate it

我有一张图片想在屏幕上多次使用,但它总是必须以不同的方式旋转。如果我使用 pygame.image.rotate 函数,它会旋转导入的图像,所以我无法单独旋转每张图像。有什么方法可以在代码中复制它然后旋转它吗?

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

如果您使用 pygame.image.load() 并将其放入一个变量中,那么只需再次放入另一个变量中即可
例如:

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
images = [pygame.image.load(path) for i in range(60)]
for i in range(len(images)):
    images[i] = pygame.transform.rotozoom(images[i],i,1) #rotate every image by 1 degree more for example
 

pygame.transform.rotate 不旋转图像本身。此函数创建图像的旋转副本和 returns 副本:

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

如果要创建多个旋转图像,则必须始终旋转原始图像。另见 How do I rotate an image around its center using PyGame?

创建图像列表:

image = pygame.image.load("assets/image")
image_list = [pygame.transform.rotate(image, ang) for ang in range(0, 360, 20)]