开发者

Path animation that advances by 'steps'

I am trying to produce a path animation in WPF. It's composed of 3 points that form a triangle. And along that path is a dot that is being animated.

So far that is all working, however, it runs smoothly as the duration progresses (as you would expect!

What I would like to happen is the animation progresses incrementally, in discrete steps. I thought I could use some kind of discrete key frame animation, but have had no luck.

So far I've got the path and the Storyboard which is (unfortunately!) working a bit too smoothly.

Is there a way to only update the animation every x seconds?

// Construct the animation path.
var pFigure 开发者_运维问答= new PathFigure
      {
       StartPoint = pathToWalk[0],
       Segments = new PathSegmentCollection
               {
                 new LineSegment(pathToWalk[1], false),
                 new LineSegment(pathToWalk[2], false),
                 new LineSegment(pathToWalk[0], false)
                }
       };


var animationPath = new PathGeometry();
animationPath.Figures.Add(pFigure);

// Freeze the PathGeometry for performance
animationPath.Freeze();


// Create a PointAnimationgUsingPath to move the Dot(EllipseGeometry)
// along the animation path.
var dotAnimation = new PointAnimationUsingPath
                 {
                 PathGeometry = animationPath,
                 Duration = TimeSpan.FromSeconds(5),
                 RepeatBehavior = RepeatBehavior.Forever
                 };

// Set the animation to target the Center property of the
// Dot(EllipseGeometry) named "theDotToAnimate".

Storyboard.SetTargetName(dotAnimation, "theDotToAnimate");
Storyboard.SetTargetProperty(dotAnimation, new PropertyPath(EllipseGeometry.CenterProperty));

// Create a Storyboard to contain and apply the animation.
var pathAnimationStoryboard = new Storyboard
                  {
                   RepeatBehavior = RepeatBehavior.Forever,
                   AutoReverse = true
                   };
pathAnimationStoryboard.Children.Add(dotAnimation);


// Start the Storyboard when ellipsePath is loaded.
dotPath.Loaded += (sender, e) => pathAnimationStoryboard.Begin(theWindowToAddto);

I thought about getting the Animation Clock from the animation and pausing and un-pausing it in a look. That might work, but it would be the ugliest thing ever!

Can anyone help?

EDIT: I also noticed IsAdditive="True" as an option, maybe there's a way of just nudging it along a bit each time?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜