Skip to content Skip to sidebar Skip to footer

Changing Direction Of Rotation Pygame

How would you change the direction of a rotating image/rect in Pygame? Applying positive and negative degree values works but it seems to only be able to rotate one direction throu

Solution 1:

As far as I know, there is only one way of rotating the image using

    pygame.transform.rotate(surface, angle)

You can check the official documentation

http://www.pygame.org/docs/ref/transform.html Here is the example code:-

    screen = pygame.display.set_mode((640,480))
    surf = pygame.image.load("/home/image.jpeg").convert()
    while True:
       newsurf = pygame.transform.rotate(surf, -90)
       screen.blit(newsurf, (100,100))
       pygame.display.flip()
       time.sleep(2)

This code will keep on rotating the image after every 2 seconds by 90 degrees in clockwise direction. Hope this helps..

Post a Comment for "Changing Direction Of Rotation Pygame"