本文介绍了如何在没有当前命令的情况下在 pygame 中旋转图像(没有 *pygame.transform.rotate* 命令)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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()
推荐答案
Oneliner using numpy:
One liners using numpy:
顺时针
pygame.surfarray.make_surface(numpy.rot90(pygame.surfarray.array2d(other1)))
逆时针
pygame.surfarray.make_surface(numpy.rot90(pygame.surfarray.array2d(other1), 3))
这篇关于如何在没有当前命令的情况下在 pygame 中旋转图像(没有 *pygame.transform.rotate* 命令)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!