[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] timer, update
> it was easy:
>
> x = pygame.time.get_ticks()
> i=0
> while 1:
> if pygame.time.get_ticks() > (x+300):
> print i
> x=pygame.time.get_ticks()
> i=i+1
Please consider something like:
x = pygame.time.get_ticks()
i=0
while 1:
pygame.wait(200)
if pygame.time.get_ticks() > (x+300):
print i
x=pygame.time.get_ticks()
i=i+1
This will allow other processes a better share of the cpu while you are
waiting.. it may need a bit of tuning in the 200 figure on different OSs
depending on how good their wait implementations are. If may trigger too much
of a context switch, but hey, try it!
Of course, if you can allow a bit less accurate timing you can use:
i=0
while 1:
pygame.wait(300)
print i
i=i+1
Regards,
Stuart.