pyglet 有报时功能吗?

Is there a function for telling time in pyglet?

我希望能够以某种方式告诉 pyglet 中的时间,可以是实际时钟时间,也可以是程序启动后的时间,有点像 pygames pygame.time.get_ticks()。

pyglet wiki 说:

from pyglet import clock
while True:
    dt = clock.tick()
    # ... update and render ...
    print 'FPS is %f' % clock.get_fps()

返回的 dt 值给出了自上次“滴答”以来的秒数(作为浮点数)。

get_fps 函数平均滑动 window 大约 1 秒的帧率。 (取dt的倒数即可算出瞬时帧率)

但我不确定 "instantaneous framerate" 是什么意思,我也不知道什么是倒数。

您可以使用 python 的 time 模块。例如

time.time() 

Return the time in seconds since the epoch as a floating point number.

time.perf_counter()

Return the value (in fractional seconds) of a performance counter, i.e. a clock with the highest available resolution to measure a short duration. It does include time elapsed during sleep and is system-wide.


在 PyGlet 中有 pyglet.clock 模块

例如FPS 可以由

确定
pyglet.clock.get_fps()

另见 Keeping track of time