1

I already read the post over here but it's different than my question.

I'm making a game, the game's main ingredient is a countdown timer (no character moving, no map only a timer) - and I'm looking for a way that I could update the screen globally every millisecond to the current time.

My question is, should I give up on having it update every millisecond or is there any way to take care of it this? Using time or just maybe pygame.Clock - if there's another way of doing a countdown timer (while in game, so it won't influence the FPS, please let me know).

Community
  • 1
  • 1
  • Pygame's clock will let you update the text every millisecond, but your screen is only going to refresh at its refresh rate, so you won't see every update. Are you ok with that? – derricw May 14 '15 at 16:08
  • you could [use `set_timer()` with `USEREVENT`](http://stackoverflow.com/q/26563033/4279), to avoid linking your timer step with fps. See [the code example there](https://gist.github.com/zed/dcc6ae76487add302371) – jfs May 16 '15 at 11:41
  • Linking [this question](https://stackoverflow.com/questions/30720665/countdown-timer-in-pygame), since it has correct answers. – skrx Aug 05 '17 at 14:50

1 Answers1

0

Yes this is possible using the pygame.time.Clock. You just use the tick method with the fps that you want. But keep in mind you are only going to see updates as fast as your screen refreshes.

clock = pygame.time.Clock()
while True:
    clock.tick(1000)  # waits until the next ms
    #clear your frame here
    #update and draw your text here
    #flip your display window here
derricw
  • 6,757
  • 3
  • 30
  • 34
  • Thanks! I didn't know it worked that way! By the way, will it affect event-handling? – Zachariah Cohen May 15 '15 at 10:54
  • I'm sorry to say, but your solution is very inaccurate - clock.tick(1) will have 1 call to the function every second. 100 would call it 100 times a second and 1000, every ms. – Zachariah Cohen May 15 '15 at 11:40
  • Oh sorry! I thought the argument was in milliseconds, not calls-per-second. Thanks for the correction! I'll update my answer. – derricw May 15 '15 at 19:29
  • @ZachariahCohen: 1000 fps is probably unrealistic. – jfs May 16 '15 at 11:44
  • This answer is wrong. The `framerate` argument that `clock.tick` takes has the purpose to limit the frame rate. – skrx Aug 05 '17 at 14:52