简体   繁体   English

如何在没有当前命令的情况下在 pygame 中旋转图像(没有 *pygame.transform.rotate* 命令)?

[英]how can i rotate an image in pygame with out current command(with out *pygame.transform.rotate* command)?

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()

One liners using numpy :一个使用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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM