how can i rotate an image in pygame with out curre

2019-09-24 03:49发布

import pygame    
SIZE = 1000, 900    
pygame.init()    
screen = pygame.display.set_mode(SIZE)    
a=0    
done = False    
screen.fill((0, 0, 0))    
other1 = pygame.image.load("image.jpg")    
screen.blit(other1, (0, 0))    
while not done:

    for event in pygame.event.get():    
        if event.type == pygame.KEYDOWN:    
            if event.key == pygame.K_LEFT:    
                a=a+90    
                other2 = pygame.transform.rotate(other1, a)    
                screen.blit(other2, (0, 0))    
            if event.key == pygame.K_RIGHT:    
                a=a-90    
                other2 = pygame.transform.rotate(other1, a)    
                screen.blit(other2, (0, 0))    
    screen.fill((0,0,0))    
    pygame.display.flip()

1条回答
孤傲高冷的网名
2楼-- · 2019-09-24 04:39

One liners using numpy:

Clockwise

pygame.surfarray.make_surface(numpy.rot90(pygame.surfarray.array2d(other1)))

Counter-clockwise

pygame.surfarray.make_surface(numpy.rot90(pygame.surfarray.array2d(other1), 3))
查看更多
登录 后发表回答