我试图按下按钮使图像旋转。当我点击屏幕时图像会旋转,但它会每隔五度继续复制一次,并且在运行一段时间后它也会崩溃。我确定有更好的方法来做到这一点,但我只是不知道它是什么。这是我的代码
while True:
for event in pygame.event.get():
'''Quit Button'''
if event.type == pygame.QUIT:
pygame.quit()
elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
screen.blit(target, targetpos)
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
# # if mouse is pressed get position of cursor ##
screen.blit(target1, target1pos)
degree = 0
while True:
image_surf = pygame.image.load('image.png')
image_surf = pygame.transform.scale(image_surf, (810, 810))
image_surfpos = image_surf.get_rect()
blittedRect = screen.blit(image_surf, image_surfpos)
'Get center of surf for later'
oldCenter = blittedRect.center
'rotate surf by amount of degrees'
rotatedSurf = pygame.transform.rotate(image_surf, degree)
'Get the rect of the rotated surf and set its center to the old center'
rotRect = rotatedSurf.get_rect()
rotRect.center = oldCenter
'Change the degree of rotation'
screen.blit(rotatedSurf, rotRect)
degree += 5
if degree > 360:
degree = 0
'Show the screen Surface'
pygame.display.flip()
'Wait 60 ms for loop to restart'
pygame.time.wait(60)
答案 0 :(得分:1)
看起来你有一个双while循环,它不会让你编写事件处理代码。也不要在每一帧真正的fps杀手
的情况下加载图像