Update pyglet.clock for Python 3.8.
@@ -44,7 +44,7 @@ games' basic requirements::
while True:
dt = clock.tick()
# ... update and render ...
- print 'FPS is %f' % clock.get_fps()
+ print(f"FPS is {clock.get_fps()}")
The ``dt`` value returned gives the number of seconds (as a float) since the
last "tick".
@@ -61,7 +61,7 @@ Scheduling
You can schedule a function to be called every time the clock is ticked::
def callback(dt):
- print '%f seconds since last callback' % dt
+ print(f"{dt} seconds since last callback")
clock.schedule(callback)
@@ -78,15 +78,15 @@ in the future::
All of the `schedule` methods will pass on any additional args or keyword args
you specify to the callback function::
- def animate(dt, velocity, sprite):
+ def move(dt, velocity, sprite):
sprite.position += dt * velocity
- clock.schedule(animate, velocity=5.0, sprite=alien)
+ clock.schedule(move, velocity=5.0, sprite=alien)
You can cancel a function scheduled with any of these methods using
`unschedule`::
- clock.unschedule(animate)
+ clock.unschedule(move)
Using multiple clocks
=====================
@@ -114,6 +114,7 @@ from __future__ import division
from builtins import range
from builtins import object
+import sys
import time
import ctypes
from operator import attrgetter
@@ -128,6 +129,9 @@ __docformat__ = 'restructuredtext'
__version__ = '$Id$'
+if sys.version_info.major < 3 and sys.version_info.minor < 5:
+ # PYTHON2 -
+
if compat_platform in ('win32', 'cygwin'):
class _ClockBase(object):
@@ -146,6 +150,14 @@ else:
_default_time_function = time.time
+else:
+
+ class _ClockBase(object):
+ def sleep(self, microseconds):
+ time.sleep(microseconds * 1e-6)
+
+ _default_time_function = time.perf_counter
+
class _ScheduledItem(object):
__slots__ = ['func', 'args', 'kwargs']
