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))
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
The function pygame.image.rotate
does not exist, however pygame.transform.rotate
does exist.
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)
See also How do I rotate an image around its center using PyGame? .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.