Problem with Update(GameTime) Methods and Pause implementation
- by Adam
I have the pause function implemented and it works correctly in that it dims the player screen and stops updating the gameplay.
The problem is that GameTime continues to increase while it is paused, so my method that checks gameTime versus previousSpawnTime before spawning another enemy gets messed up and if the game is paused too long it is noticeable that the next enemy draws far too early.
Here is my code for the enemy update.
private void UpdateEnemies(GameTime gameTime)
{
// Spawn a new enemy every 1.5 seconds
if (gameTime.TotalGameTime - previousSpawnTime > enemySpawnTime)
{
previousSpawnTime = gameTime.TotalGameTime;
// Add an Enemy
AddEnemy();
}
...
I also have other methods that depend on gameTime. I've tried getting the total pause time and subtracting that from the total game time, but I can't seem to get it to work correctly if that is the way I should go about solving this.
If you need to see any other code let me know. Thank you.