https://github.com/hexdecimal/python-tcod-clock
Track and limit the framerate of a Python program.
https://github.com/hexdecimal/python-tcod-clock
Last synced: about 1 year ago
JSON representation
Track and limit the framerate of a Python program.
- Host: GitHub
- URL: https://github.com/hexdecimal/python-tcod-clock
- Owner: HexDecimal
- License: mit
- Created: 2023-01-03T00:17:58.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-07T21:26:08.000Z (about 1 year ago)
- Last Synced: 2025-04-07T21:42:43.215Z (about 1 year ago)
- Language: Python
- Homepage:
- Size: 68.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# About
[](https://pypi.org/project/tcod-clock/)
[](https://github.com/HexDecimal/python-tcod-clock/blob/main/LICENSE)
[](https://python-tcod-clock.readthedocs.io)
[](https://codecov.io/gh/HexDecimal/python-tcod-clock)
Libtcod used to include a global framerate limiter which was eventually deprecated.
This module was created as a replacement for that feature.
```py
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=}")
```