in

Silverlight Rocks!

Resources to get the most out of Microsoft Silverlight

Silverlight game loop performance

Last post 06-25-2007 11:22 AM by Bill Reiss. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-25-2007 9:50 AM

    Silverlight game loop performance

    Hi,

    I implemented a game loop similar (mostly identical) to the storyboard engine in your examples. For a light load, it works great, but when I try to do something more practical with it, it chokes badly.

    I am having two problems:

    1. If a single frame takes too long to update (seems like about > 50ms), the whole game sputters and goes through clumps of unresponsiveness, sometimes for nearly a minute at a time! Interestingly, adding a GC.Collect() call in the update loop smooths some of it out, and if I set an interval in the storyboard that is greater than the time it takes to update a frame, performance becomes uniform again (albeit bad).

    2. Problem 1 isn't so bad, since it really shouldn't take more than 50 ms to render a frame, right? Well I have a collection of Image controls representing the game board and sprites in my game... using transparency encoded .PNGs. If I leave them all stationary, everything is fine. I can even animate a few of them (~10 per frame) without performance impact. But once I start trying to move too many of them around (15-20 per frame) the performance drops sharply. I have tried setting their position both with the Left/Top properties, and with a TranslateTransform, but the result is the same -- bad.. really bad.

    Any idea why this could be?

    Have you had any success animating 20+ image-based sprites?

    Filed under:
  • 06-25-2007 11:22 AM In reply to

    Re: Silverlight game loop performance

    I saw a post on the Silverlight.net forums which said that setting canvas.left and canvas.top will get faster in the actual release, there is a lot of debug code in there now. I have, however, done animations with more than 20 sprites (in my Dr. Popper game) and it's been OK. It's supposed to be faster to set Canvas.Top and Canvas.Left than to use a TranslateTransform. I have, however, seen a performance hit when moving sprites around in full screen, so maybe it has to do with the size of the sprites.

    Are you doing a FindName in your repositioning code, or are you finding it once and keeping a reference to the control? String lookups are inherently slow, so if you are doing any of this you may want to refactor that part.

    I'll take a look at your code if you want, and give you some advice if I see anything out of the ordinary.

    Bill Reiss
    Microsoft MVP - Client App Dev
Page 1 of 1 (2 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems