Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've been trying to figure out what is happening when I run functions from the update loop in XNA that the game freezes for a few seconds until the function is done. When I do performance testing to see how long the function is taking its lower than what is actually being taken to do the function when timed by a stop watch on my phone.

Is there something that is going on with how XNA times its updates and draws that is causing this?

I'm using XNA since MonoGame works with it.

I've got IsFixedTimeStep = false in the constructor of my game that I'm building.

For the update code:

    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            this.Exit();

        if (Keyboard.GetState().IsKeyDown(Keys.Space))
            doOnce = false;

        // TODO: Add your update logic here

        // trying to determine issue with game freezing when doing the function below.
        if (!doOnce)
        {
            doOnce = true;
            startTime = DateTime.Now;
            TestFunction();
            endTime = DateTime.Now;

            timeTakenToScale = new TimeSpan(endTime.Ticks - startTime.Ticks);
        }

        if (gameTime.TotalGameTime.TotalMilliseconds < nextFrameTime)    // don't draw the game unless its past its frame time
        {
            SuppressDraw();
            base.Update(gameTime);
        }
        else
            nextFrameTime = gameTime.TotalGameTime.TotalMilliseconds + maxFrameRate;    // set next frame to time
    }
share|improve this question
    
You've probably got fixed timing on. See msdn.microsoft.com/en-us/library/bb203878.aspx –  jzx Feb 2 at 18:32
    
It's far more likely this is an issue with how you're timing things. Either way, we'd need significantly more information about how you're timing things, what kind of debugging you're done already and what the code looks like. –  Byte56 Feb 2 at 18:33

1 Answer 1

Ok I found out the issue. Apparently when I was doing the time calculation I forgot to put totalmilliseconds and had milliseconds. Feel like an idiot for sure. :(

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.