Tuesday, 15 September 2015

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



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

why doesn't play click.wav every 444ms? seems play @ random intervals.

import pygame pygame.init() size = (700, 500) screen = pygame.display.set_mode(size) pygame.display.set_caption("444ms click") done = false clock = pygame.time.clock() noise = pygame.mixer.sound("click.wav") pygame.time.set_timer(1, 444) while not done: event in pygame.event.get(): if event.type == pygame.quit: done = true if event.type == 1: noise.play() clock.tick(60) pygame.quit()

and if knows how more good.

thank you!

@jfsebeastian: here's output the code:

447 436 443 430 449 431 448 432 910 7 407 447 442 432 446 431 448 432 450 432 446 472

use event.type == pygame.userevent + 1, otherwise event may generated other reasons (whatever 1 event type corresponds in pygame) why appears random.

the output the code shows time intervals 440±10 ms exception of 910, 7 pair.

±10 milliseconds timer sounds normal fps=60. tighter timings, utilize clock.tick() instead of clock.tick(60).

910, 7 pair suggests set_timer()/tick() might utilize time.sleep() analog somewhere. time.sleep() may sleep more specified why timer may skip beat. seek clock.tick_busy_loop() shouldn't sleep , see if can reproduce skips.

python pygame

No comments:

Post a Comment