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.
property last_fps: float

The FPS of the most recent frame.

property last_frame: float

The length of the most recent frame.

last_time

Last time this Clock was synced.

property max_fps: float

The FPS of the fastest frame.

max_samples = 64

Number of framerate samples to log. This attribute be set in the class or instance.

property mean_fps: float

The FPS of the sampled frames overall.

property median_fps: float

The FPS of the median frame.

property min_fps: float

The FPS of the slowest frame.

sync(desired_framerate=None)

Sync to a given framerate and return the delta time.

Parameters

desired_framerate (Optional[float]) – The desired framerate in seconds. If None is given then this function will track the time and framerate without ever waiting. Must be above zero when not None.

Returns

The delta time since the last call to sync, in seconds.

Return type

float

time_samples

A recent collection of delta-time samples.