My pyglet application works fine, but I feel that the FPS I'm getting is excessively high and just unnecessary CPU usage for my needs. I'm getting FPS that seems to range from 200-2000, when I really only need about 60.
In older versions of pyglet there is a function called set_fps
and all the existing help online seems to point to this deprecated function I can't use.
The pyglet docs now say that to limit stuff you should use the pyglet.clock.schedule_interval
function, which I do already use for my update
method to allow it to be called 60 times a second: pyglet.clock.schedule_interval(update, 1 / 60.0)
. This works. But I need to somehow do the same for my on_draw
event of my window. Scheduling this doesn't seem possible.
Does anyone know how to limit the FPS in pyglet?
My code isn't so different from the example game in pyglet's documentation.
window = pyglet.window.Window()
@window.event
def on_draw(): # <----- how to limit how often this is called?
# ... perform ordinary window drawing operations ...
Edit:
After bumbling around for a while I found a solution, maybe, but unsure if this is the correct way to do it:
def draw_everything(dt):
# draw stuff here
@window.event
def on_draw():
draw_everything(None)
pyglet.clock.schedule_interval(draw_everything, 1/60)
Seems the correct way of doing it is like this:
def draw_everything(dt):
# draw stuff here
@window.event
def on_draw():
draw_everything(None)
pyglet.clock.schedule_interval(draw_everything, 1/60)