Fix pew.tick() to not accumulate error over time
This commit is contained in:
parent
3826ca4194
commit
8e50aeb06f
@ -63,8 +63,12 @@ def show(pix):
|
|||||||
def tick(delay):
|
def tick(delay):
|
||||||
global _tick
|
global _tick
|
||||||
|
|
||||||
|
now = time.monotonic()
|
||||||
_tick += delay
|
_tick += delay
|
||||||
time.sleep(max(0, _tick - time.monotonic()))
|
if _tick < now:
|
||||||
|
_tick = now
|
||||||
|
else:
|
||||||
|
time.sleep(_tick - now)
|
||||||
|
|
||||||
|
|
||||||
class GameOver(Exception):
|
class GameOver(Exception):
|
||||||
|
Loading…
Reference in New Issue
Block a user