I am currently creating a game where an event happens every 800 milliseconds in pygame using the following code:
spawn_event = pg.USEREVENT + 1
pg.time.set_timer(spawn_event, 800)
for event in pg.event.get():
if event.type == spawn_event and wave == True:
spawn_enemy = True #if 800ms has passed, set spawn enemy variable to true which will spawn an enemy
The idea behind this is to spawn an enemy sprite every 800 milliseconds while a wave is in progress.
A problem arises when the game is paused however. Within the same while loop for the main game logic, there is a separate smaller while loop that runs if the game is paused.
When i resume the game after pausing in the middle of a wave, the timing seems to change and an enemy is released later than it should be, as though the timing is being reset or altered.
How can i prevent this so that the timing stays the same? Do i need to change how my game pauses?