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