From 419dc147c09106f4b3bdcccb04349e29b0e8c4e8 Mon Sep 17 00:00:00 2001 From: Plaza521 Date: Thu, 26 Oct 2023 02:12:37 +0300 Subject: [PATCH] Add timer.py Class to control fps in game --- timer.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 timer.py diff --git a/timer.py b/timer.py new file mode 100644 index 0000000..058f1fa --- /dev/null +++ b/timer.py @@ -0,0 +1,18 @@ +from time import time + + +class Timer: + def __init__(self) -> None: + self.running = False + self.old = 0 + + def control_fps(self, fps: int) -> int: + if not self.running: + self.old = time() + return + + delay_between_frames = 1 / fps + now = time() + while now - self.old < delay_between_frames: + now = time() + self.old = now