Countdown timer in Pygame

后端 未结 7 1048
眼角桃花
眼角桃花 2020-11-22 03:31

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?

相关标签:
7条回答
  • 2020-11-22 04:18

    There are several ways you can do this- here's one. Python doesn't have a mechanism for interrupts as far as I know.

    import time, datetime
    
    timer_stop = datetime.datetime.utcnow() +datetime.timedelta(seconds=10)
    while True:
        if datetime.datetime.utcnow() > timer_stop:
            print "timer complete"
            break
    
    0 讨论(0)
提交回复
热议问题