我正在尝试在WPF中生成路径动画。它由3个点组成,形成一个三角形。沿着那条路是一个动画点。
到目前为止,一切正常,但随着持续时间的推移,它会顺利运行(正如您所期望的那样!
我想要发生的是动画以不连续的步骤逐步进行。 我以为我可以使用某种离散的关键帧动画,但没有运气。
到目前为止,我的路径和故事板(不幸的是!)工作得太顺利了。
有没有办法每隔x秒更新一次动画?
// 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);
我想过从动画中获取动画时钟并暂停和暂停它。这可能有用,但这将是最丑陋的事情!
有人可以帮忙吗?
编辑:我也注意到IsAdditive =“True”作为一个选项,也许有一种方法可以让它每次都轻推一下?