8000 Fix pew.tick() to not accumulate error over time · zencuke/circuitpython@8e50aeb · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e50aeb

Browse files
committed
Fix pew.tick() to not accumulate error over time
1 parent 3826ca4 commit 8e50aeb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

frozen/pewpew10/pew.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ def show(pix):
6363
def tick(delay):
6464
global _tick
6565

66+
now = time.monotonic()
6667
_tick += delay
67-
time.sleep(max(0, _tick - time.monotonic()))
68+
if _tick < now:
69+
_tick = now
70+
else:
71+
time.sleep(_tick - now)
6872

6973

7074
class GameOver(Exception):

0 commit comments

Comments
 (0)
0