Geeks With Blogs
Sharpoverride The road to becomming a good programmer is paved with bad scripts

Need to know: In your XNA game by default the framework tries to invoke the Update() method 60 times per frame and the Draw() method as many times as possible.

You can however change this behavior by changing the values of the static properties TargetElapsedTime and IsFixedTimeStep on the Game class and the SynchronizeWithVerticalRetrace property on the GraphicsDevice class.

In your game you can adjust the call to the Update() method like so

this.TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 100.0f);

This tells the XNA framework to call your Update() method 100 times per second.

One other thing you can do is tell the framework to call the Update() method every time before the call to the Draw() method instead at regular intervals

this.IsFixedTimeStep = false;

In some cases you want to call the Draw() method at maximum intensity.

graphics.SynchronizeWithVerticalRetrace = false;

This could help you determine the maximum frame rate for your game

Note: If you instruct your game to call the Update() method 100 times per second it will try to do so at the expense of calling the Draw() method. So be very careful “With great power ..”

Posted on Saturday, August 8, 2009 6:11 AM | Back to top


Comments on this post: XNA Tip: Changing the frequency for the Update() and Draw() methods in your game

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Sharpoverride | Powered by: GeeksWithBlogs.net