Add timer.py

Class to control fps in game
dev
Plaza521 2023-10-26 02:12:37 +03:00
parent 79e400d1ea
commit 419dc147c0
Signed by untrusted user who does not match committer: nakidai
GPG Key ID: 914675D395210A97
1 changed files with 18 additions and 0 deletions

18
timer.py Normal file
View File

@ -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