1

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. 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))
Wyrden
  • 43
  • 6

2 Answers2

3

pygame.transform.rotate does not rotate the image itself. This function creates a rotated copy of the image and returns the copy:

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

If you want to create multiple rotated images, you must always rotate the original image. See also How do I rotate an image around its center using PyGame?.

Create a list of images:

image = pygame.image.load("assets/image")
image_list = [pygame.transform.rotate(image, ang) for ang in range(0, 360, 20)]
Rabbid76
  • 177,135
  • 25
  • 101
  • 146
0

If you use pygame.image.load() and put it in a variable, then just put again in another one
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
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
 
S H
  • 331
  • 1
  • 13
  • the problem is that i need many of these images like 60 or something so i dont want to rotate every image on its own but i will do that if there is no other way – Wyrden Jan 23 '22 at 19:56
  • you can create a list of images, i will update my post to show you – S H Jan 23 '22 at 20:10
  • I hope it solves your problem – S H Jan 24 '22 at 14:35