Share this post

Link to post

Share on other sites

What you could do is in MultipleEnemies(), set a member called lastTime=0. Then in Update() you would set time=gameTime.TotalGameTime.Seconds, then set a local variable deltaTime=time-lastTime. This would give the amount of time since the last time through the Update loop. If this value is greater than 1 second, increment SpawnNextEnemy. At the end of Update set lastTime=time. This way, you don't have to worry about setting your main game timer to 0. You are always keeping track of the last time Update was called, and using the elapsed time to determine whether to spawn an enemy.

1

Share this post

Link to post

Share on other sites

What you could do is in MultipleEnemies(), set a member called lastTime=0. Then in Update() you would set time=gameTime.TotalGameTime.Seconds, then set a local variable deltaTime=time-lastTime. This would give the amount of time since the last time through the Update loop. If this value is greater than 1 second, increment SpawnNextEnemy. At the end of Update set lastTime=time. This way, you don't have to worry about setting your main game timer to 0. You are always keeping track of the last time Update was called, and using the elapsed time to determine whether to spawn an enemy.