In a loop, the system responds to the pressing of a key on the keyboard, then performs two operations, and then responds to the pressing of the same key on the keyboard again, but only performs the second operation. What should be done?
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
sys.exit()
elif event.key == pygame.K_RIGHT:
tank.update1()
tank.moving_right = True
For example, in the elif statement, starting from the second time, only tank.moving_right = True will be executed instead of tank.update1()
How to deal with it
tank里面加开关标志
添加个标志变量