Welcome to tcod-clock’s documentation!#
About#
Libtcod used to include a global framerate limiter which was eventually deprecated. This module was created as a replacement for that feature.
import time
import tcod.clock
FPS = 30
end_time = time.time() + 3 # Loop for 3 seconds.
clock = tcod.clock.Clock()
while time.time() < end_time:
clock.sync(1 / FPS) # This loop will run at 30 FPS until interrupted.
# Timing information can be checked. Check the docs for more info.
print(f"{clock.last_fps=}")
print(f"{clock.min_fps=}")
print(f"{clock.max_fps=}")
print(f"{clock.mean_fps=}")
print(f"{clock.median_fps=}")
API reference#
Track and limit framerate of a program.
- class tcod.clock.Clock#
Bases:
object
Measure framerate performance and sync to a given framerate.
Everything important is handled by
Clock.sync
. You can use the fps properties to track the performance of an application.Time is sampled with
time.perf_counter
.Example:
import tcod.clock clock = tcod.clock.Clock() while True: clock.sync(1 / 30) # This loop will run at 30 FPS until interrupted.
- last_time#
Last time this Clock was synced.
- max_samples = 64#
Number of framerate samples to log. This attribute be set in the class or instance.
- sync(desired_framerate=None)#
Sync to a given framerate and return the delta time.
- time_samples#
A recent collection of delta-time samples.