Python Forum
How do I use pygame.transform.rotate()? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: How do I use pygame.transform.rotate()? (/thread-24787.html)



How do I use pygame.transform.rotate()? - noodlespinbot - Mar-04-2020

Hello! I used pygame.transform.rotate() in my code, but it didn't work.
Help!:
import pygame

pygame.init()

spotlight = pygame.display.set_mode((700, 600))

pygame.display.set_caption("Spotlight")
Mouse_x, Mouse_y = pygame.mouse.get_pos()
x = 40
y = 40
vel = 20
a = 255
b = 255
c = 255
drift = 0


run = True
while run:
    pygame.time.delay(100)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    spotlight.fill((0, 0, 0))


        


    pygame.transform.rotate(spotlight, drift)   


    pygame.draw.rect(spotlight, (a, b, c), (x, y, 40, 25))
    pygame.display.update()

    keys = pygame.key.get_pressed()   
        

    if keys[pygame.K_LEFT]:
        drift-= vel
 
 
    if keys[pygame.K_RIGHT]:
        drift+= vel

 
    if keys[pygame.K_UP]:
        y-= vel
 
 
    if keys[pygame.K_DOWN]:
        y+= vel
 
pygame.quit()



RE: How do I use pygame.transform.rotate()? - michael1789 - Mar-05-2020

You are trying to rotate the screen. You need to rotate an image on the screen.

Something like this:
square = pygame.Surface((30, 30))
square.fill((255, 0, 0))
rotated_square = pygame.transform.rotate(square, 45)