Problem with Update(GameTime) Methods and Pause implementation

Posted by Adam on Game Development See other posts from Game Development or by Adam
Published on 2012-03-26T20:35:02Z Indexed on 2012/03/26 23:40 UTC
Read the original article Hit count: 196

Filed under:
|
|
|

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.

© Game Development or respective owner

Related posts about XNA

Related posts about c#