I read about get_time() method on Pygame documentation and other
then try to coding but its output it's not same i think
this below is my code
and output
i think it will print 10 but it's not show.
Anybody can tell me how get_time() method work?
I read about get_time() method on Pygame documentation and other
then try to coding but its output it's not same i think
this below is my code
and output
i think it will print 10 but it's not show.
Anybody can tell me how get_time() method work?
For the next time, please use a code block to insert code in a post (the "</>" symbol in the editor), it makes copy/paste possible which saves time and eliminates typos.
As for question, actually, it outputs "0" after 1000 seconds as per https://docs.python.org/3/library/time.html?highlight=time%20sleep#time.sleep
It looks like it works as intended to me. I am not sure why you think outputs 10, as you haven't even called "a.tick()" twice in the code so there isn't a "time between the previous two calls to tick" as apparently needed by get_time().
As I never used pygame.time.Clock, I can;t help you much further, but hopefully I left a few pointers to get you on your way again.
You have to call pygame.init() I think then
call a.tick() after sleep to update the clock
then you can call get_time() successfully
</
import pygame,time
pygame.init()
print("hello")
a=pygame.time.Clock()
a.tick()
#time.sleep(1000)
time.sleep(10)
a.tick()
print(str(a.get_time()))
>
Doug
The other option would be to use 'get_rawtime' which should not factor in any extra time between ticks.
This will wait 10 seconds and then display the time in seconds and quit.
import pygame,time
import sys
pygame.init()
print("hello")
a=pygame.time.Clock()
a.tick()
pygame.time.wait(10000)
a.tick()
stop_time = (int)(a.get_rawtime() / 1000)
print(str(stop_time))
pygame.quit()
sys.exit()
jomodev said:
stop_time = (int)(a.get_rawtime() / 1000)
Python 3 has // for integer division, so you can do "stoptime = a.getrawtime() // 1000" without having to cast to an integer.