Pygame 中的倒数计时器 [英] Countdown timer in Pygame

查看:124
本文介绍了Pygame 中的倒数计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 pygame 并且我想做简单的游戏.我需要的元素之一是倒数计时器.如何在 PyGame 中进行倒计时(例如 10 秒)?

I started using pygame and I want to do simple game. One of the elements which I need is countdown timer. How can I do the countdown time (eg 10 seconds) in PyGame?

推荐答案

在此页面上,您将找到您要查找的内容 http://www.pygame.org/docs/ref/time.html#pygame.time.get_ticks
您在开始倒计时之前下载一次滴答声(这可能是游戏中的触发器 - 关键事件,无论如何).例如:

On this page you will find what you are looking for http://www.pygame.org/docs/ref/time.html#pygame.time.get_ticks
You download ticks once before beginning the countdown (which can be a trigger in the game - the key event, whatever). For example:

start_ticks=pygame.time.get_ticks() #starter tick
while mainloop: # mainloop
    seconds=(pygame.time.get_ticks()-start_ticks)/1000 #calculate how many seconds
    if seconds>10: # if more than 10 seconds close the game
        break
    print (seconds) #print how many seconds

这篇关于Pygame 中的倒数计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆