I have created a game that has two cars who race each other by tapping buttons quicker than the other. So i want to make it where after the race ends it prints out how long it took for the winner of the race to make it to the finish line. I have tried using pygame.time.get_ticks() however that gives the time of how long since pygame.init() was called.
            Asked
            
        
        
            Active
            
        
            Viewed 88 times
        
    0
            
            
         
    
    
        Petras99
        
- 45
- 6
- 
                    See the answer here: http://stackoverflow.com/questions/7370801/measure-time-elapsed-in-python – marienbad Apr 28 '16 at 03:32
- 
                    Thank you, i will look over it and see how it works – Petras99 Apr 28 '16 at 05:13
1 Answers
0
            You can use pygame.time.get_ticks().
Set a start time and an end time and measure the difference:
import pygame as py
py.init()
clock = py.time.Clock()
start_time = py.time.get_ticks()
print "started at:",start_time
for i in xrange(0,30): #wait 1 second
    clock.tick(30)
end_time = py.time.get_ticks()
print "finished at:",end_time
time_taken = end_time-start_time
print "time taken:",time_taken
 
    
    
        DCA-
        
- 1,262
- 2
- 18
- 33