我试图让我的定时器不断添加,当我们点击e,但我不知道为什么我要保持e定时器不断增加我的定时器名称是(吨)是否有一种方法,我可以继续添加我的定时器,当我们点击e而不是停止,当我们不再点击e,我尝试了'if事件。输入== pygame。K_e'但这是一样的我必须保持e
if keys[pygame.K_e]: # if we click e then it should keep adding tons
tons += 1
print(tons)
游戏循环
run = True
while run:
# Making game run with fps
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# telling what to do when we say the word 'key'
keys = pygame.key.get_pressed()
if hit:
if keys[pygame.K_e]: # if we click e then it should keep adding tons
tons += 1
print(tons)
if tons > 10:
playerman.direction = "att"
if health2 > -21:
health2 -= 0.3
else:
playerman.direction = "Idle"
hit = False
if tons > 30:
tons = 0
playerman.direction = "Idle"
但我不知道为什么我必须保持e定时器继续添加
因为你就是这么写的。看看你的代码:
if keys[pygame.K_e]: # if we click e then it should keep adding tons
tons += 1
tons
当且仅当e被按下时递增。
是否有一种方法可以在我们点击e时继续添加定时器而不是在我们不再点击e时停止定时器
只是设置一个标志,像这样:
pressed_e = False
run = True
while run:
for event in pygame.event.get():
...
if event.type == pygame.KEYDOWN and event.key == pygame.K_e:
pressed_e = True
if pressed_e: # if we click e then it should keep adding tons
tons += 1
...