pygame-clock

How to create timers in pygame efficiently?

How to create timers in pygame efficiently? Question: I want to spawn an enemy every (some number) seconds, say 5. I could do: start_time = pygame.time.get_ticks() if pygame.time.get_ticks() – start_time >= (some number): spawn_enemy() But there’s one problem with that: when I change the FPS (clock.tick()) from 120 to say 60 then the enemy spawn …

Total answers: 1

pygame clock.tick() vs framerate in game main loop

pygame clock.tick() vs framerate in game main loop Question: Every pygame has a game loop that looks like this: while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.display.flip() print(“tick ” + str(pygame.time.get_ticks())) clock.tick(1) According to the api forget_ticks(): Returns the number of millisconds since pygame.init() was called. Before pygame is …

Total answers: 4