Welcome to MSDN Blogs Sign in | Join | Help

You had me at "Hello World!"

XAML, WPF, Silverlight, .NET, Office 2007, Windows code samples and other interesting things

Syndication

Exposed: 5 methods to create game loop: which is the best?

Edit: fixed broken links

What is the best method to create a game loop?

I created a small experiment comparing 5 different animation methods.

The results, along with code samples and test screenshots are summarized in this document:

5 Game Loops in Silverlight: Which is the best? (PDF)

5 Game Loops in Silverlight: Which is the best? (DOCX)

Sample test app (requires reading the document above to understand the setup): http://nokola.com/gamelooptest

This is part of the test app startup screen before measurements begin:

 

Contents of the doc:
Welcome
What Are Some Things Important For A Game?
Why Are We Discussing Game Loops?
Methods
Test Setup
Test Results
  MaxFrameRate Unset (Defaults to 60):
    Analysis of the 60 FPS default case:
  MaxFrameRate=300:
    Analysis of the 300 FPS case:
  Additional Tips
  Quick Comparison Chart
Summary & Conclusion

 

I hope this will shed some light on Silverlight game loop that several people on this blog asked so far!

Please let me know what you think!

Published Wednesday, August 19, 2009 8:57 AM by nikola


Attachment(s): gameloop.jpg

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Exposed: 5 methods to create game loop: which is the best? @ Monday, August 24, 2009 12:59 AM

Nikola, I'm anxious to see what you have found, but the links to your document seem to be broken.

Isak

# Broken links? @ Monday, August 24, 2009 4:15 AM

Hmm... I get 404 errors when I try to download either version of the documents.

Igor Ostrovsky

# re: Exposed: 5 methods to create game loop: which is the best? @ Monday, August 24, 2009 4:55 AM

I can't reach livefilestore.com. Can you make the docs available somewhere else?

John Sietsma

# re: Exposed: 5 methods to create game loop: which is the best? @ Monday, August 24, 2009 5:29 AM

Thank you all for the note! The broken links are fixed now - please try again!

Thanks,

Nikola

nikola

# re: Exposed: 5 methods to create game loop: which is the best? @ Monday, August 24, 2009 10:08 PM

I have much much lower aveage with CompositionTarget.Rendering than any of the other examples, probably because it runs with a greater framerate for me. But thats the great thing about that loop... you only set the translate when you need to, and as often as you need to; no more, no less.

Also I noticed that if I drag the browser window around, the stability of the other methods are all over the place, while CompositionTarget stays constant.

SharpGIS

# re: Exposed: 5 methods to create game loop: which is the best? @ Tuesday, August 25, 2009 2:44 AM

This is good to know, thanks for doing this research!

About method 5, though - that method is a little different from what the Farseer physics sample uses. They use the same concept as you, except they do not have this line:

_sbTrigger.Duration = TimeSpan.FromMilliseconds(10);

So they don't set a duration. I compiled your project commenting out this line, and the results changed. With this method, the

"Storyboard as trigger" method has the same time between frames as CompositionTarget.Rendering. CompositionTarget.Rendering still has a little lower variance of time between frames, however.

I think I'll go with Storyboard as Trigger, then. (I'm working on a space shooter) It is very close to being as smooth as CompositionTarget.Rendering, and seems to be easier to implement. (at least if one wants to avoid the problem you had with your first starfield)

Isak

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
Page view tracker