开发者

WPf animation with WinMM

I would like some informations about animation in WPF

because i need really accurate rendering, i've decide to use a Multimedia timer instead of the default animation timer...

So I would like to know how does the animation clock work... i was thinking of raising tick event every 2ms and call a dispatcher invoke (i'm not sure that 2ms interval is enought for moving a line but if my understanding is good, dispactcher will manage that, no ?!?

public v开发者_如何学运维oid setTime(int TimeInMs)
        {
         AnimatedLine.Dispatcher.Invoke(
         System.Windows.Threading.DispatcherPriority.Normal,
         new Action(
           delegate()
           {
               AnimatedLine.X1 = TimeInMs / 10 * ZoomRatio;
               AnimatedLine.X2 = TimeInMs / 10 * ZoomRatio;
           }
       ));

is it the best way of doing that ?

Moreover, i would like to know how you can test some collection every 2ms ...

For now, i really think that it's impossible to loop a collection every 2ms (for example of 100 objects) so i've decide to use a dictionnary ... (using the Key as time reference ..) if there is better option i'll be glad to hear ...


Don't do that. If the main thread can't cope with modifing+rerendering your visuals, Actions will stack up in the Dispatcher until something really bad happens.

Instead, take a look at CompositionTarget.Rendering. Basically, This event is raised once per frame, so you can animate your objects in it before rendering.

Of course, there is no notion of frame rate here, and you can't predict at which interval this event is raised. So consider basing your animation on the time elapsed since last frame.

It's good animation practice anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜