如何使用out current命令在pygame中旋转图像(使用out * pygame.transform.rotate *命令)?

时间:2017-02-10 07:24:10

标签: python rotation

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 个答案:

答案 0 :(得分:0)

使用numpy的一个衬垫:

顺时针

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

逆时针

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