如果按住某个键,我试图在屏幕上移动球。
两天前(这是我开始学习pygame的时候),我一直在寻找解决方案,但似乎找不到。
if event.type == pygame.KEYDOWN:
isPressed = True
if pygame.key.get_pressed()[pygame.K_LEFT]: xSpeed -= speed
if pygame.key.get_pressed()[pygame.K_RIGHT]: xSpeed += speed
if pygame.key.get_pressed()[pygame.K_UP]: ySpeed -= speed
if pygame.key.get_pressed()[pygame.K_DOWN]: ySpeed += speed
elif event.type == pygame.KEYUP:
if pygame.key.get_pressed()[pygame.K_LEFT] or [pygame.K_RIGHT] or [pygame.K_UP] or [pygame.K_DOWN]:
isPressed = False
if isPressed == True:
#move the ball
display.blit(ball, (xSpeed, ySpeed))
pygame.display.flip()
display.blit(background, (0, 0))