Python Forum
How do I use pygame.transform.rotate()?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I use pygame.transform.rotate()?
#1
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()
Reply
#2
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] How to rotate images LavaCreeperKing 12 15,990 Jan-04-2020, 04:21 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020