Answered Animating many objects in WPF

  • Sunday, July 27, 2008 9:47 AM
     
     
    I'm going to animate many objects (at least a few hundreds, ~500-700) at the same time in WPF (generally changing their positions; for example simple, small rectangles). The problem is, that it needs a lot of CPU. I'm using DoubleAnimation Class. Is there a way to make it work the same way (i.e. as smoot as now) but using less resources? Or maybe should I resign from WPF and use something else? I would be grateful for any proposals :).

Answers

  • Tuesday, July 29, 2008 8:51 PM
     
     Answered Has Code
    Hi,

    I'm sorry it took me so much time to reply, but I was busy recently.

    Unfortunately it didn't help... Now it's even worse - with 400 objects animating on the screen at the same time the CPU usage is higher (~80%) than previously...

    **EDIT**

    Whoa! I think I've just found the solution! The following code reduces the CPU consumption to ~15%-20%:


    Timeline.DesiredFrameRateProperty.OverrideMetadata(
                    typeof(Timeline),
                    new FrameworkPropertyMetadata { DefaultValue = 20 }
                    );

    It just makes the animation a bit slower by reducing the framerate to 20 frames per second. Maybe the animation is not as smooth as it used to be, but that's not the most important thing in my project.
    • Edited by Jajo.ovo Tuesday, July 29, 2008 9:06 PM I found the solution
    • Marked As Answer by Marco Zhou Wednesday, July 30, 2008 8:21 AM
    •  

All Replies

  • Sunday, July 27, 2008 10:23 AM
     
     
    Hi,

    Try to put your Storyboard in a ParallelTimeline element: http://msdn.microsoft.com/en-us/library/system.windows.media.animation.paralleltimeline.aspx
    Thomas Lebrun [MVP] - WPF/LINQ: http://blog.developpeur.org/tom - http://morpheus.developpez.com
  • Tuesday, July 29, 2008 8:51 PM
     
     Answered Has Code
    Hi,

    I'm sorry it took me so much time to reply, but I was busy recently.

    Unfortunately it didn't help... Now it's even worse - with 400 objects animating on the screen at the same time the CPU usage is higher (~80%) than previously...

    **EDIT**

    Whoa! I think I've just found the solution! The following code reduces the CPU consumption to ~15%-20%:


    Timeline.DesiredFrameRateProperty.OverrideMetadata(
                    typeof(Timeline),
                    new FrameworkPropertyMetadata { DefaultValue = 20 }
                    );

    It just makes the animation a bit slower by reducing the framerate to 20 frames per second. Maybe the animation is not as smooth as it used to be, but that's not the most important thing in my project.
    • Edited by Jajo.ovo Tuesday, July 29, 2008 9:06 PM I found the solution
    • Marked As Answer by Marco Zhou Wednesday, July 30, 2008 8:21 AM
    •