pygame.time.set_timer() - 4 2 the floor click

后端 未结 1 741
花落未央
花落未央 2020-12-12 04:55

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         


        
相关标签:
1条回答
  • 2020-12-12 05:30

    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.

    0 讨论(0)
提交回复
热议问题