How to efficiently hold a key in Pygame?

前端 未结 7 1714
谎友^
谎友^ 2020-12-11 07:10

I\'ve found two related questions:

  • Pygame hold key down causes an infinite loop
  • pygame - on hold button down

But I want to be specific. H

7条回答
  •  醉话见心
    2020-12-11 07:20

    I am using a different approach on holding down a key that I am using in the specific task of moving an object left or right.

    I do not care about the computer knowing that a key is actually held down.

    When I press a key, a variable that I define for that key (EG: left arrow) is set to True. Until that key is unpressed (with the event pygame.KEYUP) the "movement to left" is performed.

提交回复
热议问题