我正在尝试在我的python游戏的右上角添加一个倒数计时器

时间:2012-05-02 22:48:12

标签: python timer pygame countdown

我不想导入除pygame以外的任何内容......>>我的游戏速度为50 fps 我的屏幕是640x480

我正在尝试在屏幕右上角添加一个计时器。计时器需要从10开始倒计时......我已经尝试了很多东西而无法让它工作。到目前为止,这就是我所拥有的:

class Timer(games.Sprite):
    """ countdown timer """
    def __init__(self):
       timer_message = games.Text(
       value = 10,
       size = 50,
       color = color.black,
       x = games.screen.width - 30,
       y = games.screen.height - 420)
    timer_delay = 50

1 个答案:

答案 0 :(得分:1)

我没有看到任何实际导致计时器倒计时的代码。在不了解其余代码的情况下,我建议使用

class Timer(games.Sprite):
    def __init__(self):
        ....
        self.start()

    def start(self):
        while self.timer_message.value != 0:
            time.sleep(1)
            self.timer_message.value -= 1

不要为分配timer_delay而烦恼。