import time # add this line
....
running = True
start_time = time.time() # game start - add this line
while running:
......
draw_text(screen, str(score), 18, WIDTH / 2, 10)
draw_text(screen, str(int(time.time() - start_time)), 18, 15, HEIGHT-20) # game timer - add this line
draw_shield_bar(screen, 5, 5, player.shield)
这里有一个更简单的解决方案,只需要一条新线路
draw_text(screen, str(score), 18, WIDTH / 2, 10)
draw_text(screen, str(int(pygame.time.get_ticks()/1000)), 18, 15, HEIGHT-20) # game timer - add this line
draw_shield_bar(screen, 5, 5, player.shield)
在pygame中,有几种方法可以获取当前游戏时间
pygame.init()
以来的毫秒数只需添加几行代码即可获得计时器
这里有一个更简单的解决方案,只需要一条新线路
相关问题 更多 >
编程相关推荐