Why doesn\'t this play my click.wav every 444ms? it just seems to play it at random intervals.
import pygame
pygame.init()
size = (700, 500)
screen = pygame
Use event.type == pygame.USEREVENT + 1
, otherwise the event may be generated for other reasons (whatever 1
event type corresponds to in pygame) that is why it appears random.
The output for the code shows that the time intervals are mostly 440±10
ms with the exception of 910
, 7
pair.
±10
milliseconds for a timer sounds normal for fps=60
. To get tighter timings, you could use clock.tick()
instead of clock.tick(60)
.
910
, 7
pair suggests that set_timer()
/tick()
might use a time.sleep()
analog somewhere. time.sleep()
may sleep more than specified that is why the timer may skip a beat. Try clock.tick_busy_loop()
that shouldn't sleep and see if you can reproduce the skips.