Adjusting the Animation Speed

While adjusting the framerate of the game itself does affect the three rings animation speed, it's not the ideal way to do so. Why is that? When you change the framerate for the project, it will affect the animation speed of all images, as well as things like the speed of moving objects and so on. If you wanted one image to animate at 60 fps and another to animate at 30 fps, you wouldn't be able to accomplish that by adjusting the overall game's framerate.

Remove the line you added in the previous section that set the TargetElapsedTime member of the Game1 class, and let's try a different route.

When adjusting a sprite's animation speed, you typically want to do so for that sprite alone. This can be done by building in a way to move to the next frame in the sprite sheet only when a specified time has elapsed. To do this, add two class-level variables, which you'll use to track the time between animation frames:

int timeSinceLastFrame = 0;
int millisecondsPerFrame = 50;

The timeSinceLastFrame variable will be used to track how much time has passed since the animation frame was changed. The millisecondsPerFrame variable will be used to specify how much time you want to wait before moving the current frame index.

The actual cycling of animation frames happens in your Update method. So, the next step is to check the elapsed time between animation frames and run the code that moves the current frame only if the desired elapsed time has been reached. Modify the ...

Get Learning XNA 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.