0

Hey i am trying to get a timer for my game how do i reset this

start_ticks=pygame.time.get_ticks() #starter tick
while mainloop: # mainloop
    seconds=(pygame.time.get_ticks()-start_ticks)/1000 #calculate how many seconds
    if seconds>10: # if more than 10 seconds close the game
        break
    print (seconds) #print how many seconds

thank you all for helping =)

1 Answers1

0

Your timer starts at the time stored in the variable start_ticks. If you want to rest the timer, you must therefore set a new value for the start_ticks variable. Assign the current time (pygame.time.get_ticks()) to start_ticks when the timer needs to be reset:

start_ticks = pygame.time.get_ticks() 
while mainloop:
   
    seconds = (pygame.time.get_ticks() - start_ticks)/1000
    if seconds > 10:
        start_ticks = pygame.time.get_ticks() 
Rabbid76
  • 177,135
  • 25
  • 101
  • 146