How do I get my object in pygame to move by holding the button?

前端 未结 3 1507
猫巷女王i
猫巷女王i 2021-01-21 23:47

I tried using something like this but it did not work.

while running:
keys = pygame.key.get_pressed()  #checking pressed keys
if keys[pygame.K_UP]:
    y1 -= 1
i         


        
3条回答
  •  滥情空心
    2021-01-22 00:25

    One solution to this problem would be to use set_repeat function

    pygame.key.set_repeat(True)
    

    This will generate multiple KEYDOWN events.

提交回复
热议问题