0
pygame我想要使用每个箭头键在每个方向上10%的图像翻译图像。现在我使用的代码只要按下按键就会移动图像,我想要的是仅仅移动一次,无论按键是否仍然按下。Pygame单推事件
if event.type == KEYDOWN:
if (event.key == K_RIGHT):
DISPLAYSURF.fill((255,255,255)) #Clears the screen
translation_x(100)
draw(1)
if (event.key == K_LEFT):
DISPLAYSURF.fill((255,255,255)) #Clears the screen
translation_x(-100)
draw(2)
if (event.key == K_UP):
DISPLAYSURF.fill((255,255,255)) #Clears the screen
translation_y(100)
draw(3)
if (event.key == K_DOWN):
DISPLAYSURF.fill((255,255,255)) #Clears the screen
translation_y(-100)
draw(4)
有没有除了使用time.sleep
你可以停止,直到你收到相应的按键了事件的关键的关键下来后反应。 – flup
根据[pygame的文档](http://www.pygame.org/docs/ref/key.html),只有一个keydown事件被接收,直到该键被释放并随后再次按下。你确定接受连续的keydown事件是你问题的根源吗? – kevintodisco
ktodisco是对的。什么是'draw(int)'在做什么? ---另一种方法是获取按键状态,该按键状态轮询按键是否被按下。 – ninMonkey