我正在尝试在按下键时移动图像。它移动但不流畅,按下按钮时它不会继续移动。
import pygame, sys
from pygame.locals import *
white=(255,255,255)
black=(0,0,0)
pygame.init()
window=pygame.display.set_mode((640, 360),0,32)
image=pygame.image.load("white.png")
image.set_colorkey(white)
x,y=0,0
movex,movey=0,0
while True:
window.fill(black)
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_LEFT:
movex+=-1
elif event.key==K_RIGHT:
movex+=1
elif event.key==K_UP:
movey+=-1
elif event.key==K_DOWN:
movey+=1
x=movex
y=movey
window.blit(image,(x,y))
pygame.display.update()