libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
410 stars 36 forks source link

Limit the FPS with the new API #97

Closed Darky-Lucera closed 3 years ago

Darky-Lucera commented 4 years ago

I'm trying to modernize my roguelike source code using the new API and I cannot find a method to limit the FPS. In the old version I was doing:

tcod.sys_set_fps(20)

Is there any way to do this with the new API? Instead of doing it manually from my code skipping frames

HexDecimal commented 4 years ago

There isn't anything builtin to python-tcod right now. The FPS limit was hard coded into the previous API and the new one doesn't have anything similar. You can take PyGame's Clock if you don't want to write your own limiter, but it isn't hard to write a new one in Python. There was nothing special about the old limiter.

If you're having trouble then I could write something quick right now, but it'd just be a port of Clock.

Darky-Lucera commented 4 years ago

just to avoid the deprecated message:

main.py:76: DeprecationWarning: This function is not supported if contexts are being used. tcod.sys_set_fps(20)

Probably I will do my own, so I can have the effects at 60 FPS and player/enemy states at 20 FPS (60 is too fast for this).

Note: I don't know PyGame but in Python 3.7, the time module gains ns resolution timers.

Thanks!

HexDecimal commented 3 years ago

I've finished an example script for handling the frame rate. I now recommend copying this script if you need to set a specific frame rate.