Skip to Main Content
Learning XNA 3.0
book

Learning XNA 3.0

by Aaron Reed
November 2008
Beginner content levelBeginner
510 pages
16h 24m
English
O'Reilly Media, Inc.
Content preview from Learning XNA 3.0

Adjusting the Framerate

While the three rings animation looks pretty decent when you run the project, there may be a time when your animation runs too quickly or too slowly and you want to change the speed at which it animates.

I mentioned the framerate earlier, but here's a quick reminder: framerate generally refers to how many times per second a game redraws the entire scene. In XNA, the default is 60 frames per second (fps). Unless you're running the current project on a very slow machine, you're most likely seeing the three rings image project being drawn at 60 fps.

There is also a different type of framerate, related to individual animations. This framerate (often referred to as the animation speed) reflects the rate at which a given animation cycles through images in the sprite sheet. Right now, your animation speed for the three rings image is 60 fps, because you are drawing a new image from the sprite sheet every time you redraw the scene (which is happening at 60 fps).

There are a few different ways you can change the animation speed of your three rings animation. XNA's Game class has a property called TargetElapsedTime that tells XNA how long to wait between calls to the Game.Update method. Essentially, this represents the amount of time between each frame being drawn. By default this is set to 1/60 of a second, which gives XNA the default 60 fps.

To change the framerate of your project, add the following line of code at the end of the Game1 constructor:

TargetElapsedTime = ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning XNA 4.0

Learning XNA 4.0

Aaron Reed
Beginning C# 7 Programming with Visual Studio 2017

Beginning C# 7 Programming with Visual Studio 2017

Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid

Publisher Resources

ISBN: 9780596154905Supplemental ContentErrata Page