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