Animate a path?

2019-04-11 08:16发布

问题:

I have a set of coordinates. I would like to take, for instance, the first 5 and draw a line connecting 1 to 2 to 3 to 4 to 5. Then after a pre-determined duration, I'd like to remove the first point and add the 6th point. In doing that, I'd like the line to animate in such a way as the "beginning" of the line moves from point 1 to point2, while the end of the line moves from point 5 to point 6.

The effect here would look a lot like the old game Nibbles with the snake that moves around eating stuff.

What would be the most efficient way to approach this in WPF?

Thanks in advance!

回答1:

I would use the Polyline and manipulate the Points collection by simply adding and removing the points. See msdn for example code.



回答2:

Going to post a rough outline of my solution here. I actually ended up using a PathGeometry object and a set of DoubleAnimationUsingPath animations to get what I wanted. Polyline (suggested by Damokles) got me going in the right direction, but it wasn't until I found the DoubleAnimationUsingPath class that I was able to take it where I wanted to go.



标签: wpf animation