【问题标题】:Animation AutoReverse = false but does it anyway and starts from the wrong starting pointAnimation AutoReverse = false 但无论如何都会这样做并从错误的起点开始
【发布时间】:2014-06-18 06:19:41
【问题描述】:

我正在尝试从画布的右下角到画布的左上角获取图像,并永远重复此行为。图像不应该从左上角到右上角进行反向动画。我是动画新手,所以我使用了this example

目前我的图像正在从左上角移动到右下角并返回。我尝试更改画布中图像的起始位置,结果动画将此位置用作新的起点。我还尝试使用负值,让图像向相反方向移动。减少片段中的点数让我的动画路径更短,但没有别的。我还设置了 AutoReverse=false,动画行为没有任何变化。

我的想法是, - 段类正在用点构建一个圆圈,但是要使用哪个其他类? - 开始位置必须改变,但如何让对象在屏幕上向上移动而不是向下移动?

我的代码,

Storyboard animationSB = new Storyboard();

//Image book = createImage(model.keywordCollection[0].cover.small);
Image rope1 = createImage("pack://application:,,,/GUI;component/Resources/rope_trans.png");
rope1.Height = 360.0;
rope1.Width = 185.0;

//Transform to move the book image
TranslateTransform aniRope1 = new TranslateTransform();
this.RegisterName("AnimatedRope1", aniRope1);
rope1.RenderTransform = aniRope1;
Canvas.SetLeft(rope1, 258.659);
Canvas.SetTop(rope1, 583.212);
LeftRope.Children.Add(rope1);


//Anitmation path
PathGeometry animationPath1 = new PathGeometry();
PathFigure pathFigure1 = new PathFigure();
PolyLineSegment lineSegments1 = new PolyLineSegment();
lineSegments1.Points.Add(new Point(LeftRope.ActualWidth, LeftRope.ActualHeight));
lineSegments1.Points.Add(new Point(258.659, 583.212));
lineSegments1.Points.Add(new Point(120.596, 272.665));
lineSegments1.Points.Add(new Point(0, 0));
pathFigure1.Segments.Add(lineSegments1);
animationPath1.Figures.Add(pathFigure1);
animationPath1.Freeze();

//Animate transform to move image along the path on the x-axis
DoubleAnimationUsingPath translateXAnimation1 = new DoubleAnimationUsingPath();
translateXAnimation1.PathGeometry = animationPath1;
translateXAnimation1.Duration = TimeSpan.FromSeconds(6);
translateXAnimation1.Source = PathAnimationSource.X;
translateXAnimation1.AutoReverse = false;

Storyboard.SetTargetName(translateXAnimation1, "AnimatedRope1");
Storyboard.SetTargetProperty(translateXAnimation1, new PropertyPath(TranslateTransform.XProperty));

//Animate transform to move image along the path on the y-axis
DoubleAnimationUsingPath translateYAnimation1 = new DoubleAnimationUsingPath();
translateYAnimation1.PathGeometry = animationPath1;
translateYAnimation1.Duration = TimeSpan.FromSeconds(6);
translateYAnimation1.Source = PathAnimationSource.Y;
translateYAnimation1.AutoReverse = false;

Storyboard.SetTargetName(translateYAnimation1, "AnimatedRope1");
Storyboard.SetTargetProperty(translateYAnimation1, new PropertyPath(TranslateTransform.YProperty));

//Create Storyboard containing and applying the animation

//animationSB.RepeatBehavior = RepeatBehavior.Forever;
animationSB.Children.Add(translateXAnimation1);
animationSB.Children.Add(translateYAnimation1);

animationSB.AutoReverse = false;

情节提要以另一种方法启动。

我正在使用 .Net 4.5.1 C# 桌面应用程序在 Windows 8.1N 上进行开发。

【问题讨论】:

    标签: c# .net wpf animation .net-4.5


    【解决方案1】:

    你应该换行:

    lineSegments1.Points.Add(new Point(LeftRope.ActualWidth, LeftRope.ActualHeight));
    

    pathFigure1.StartPoint = new Point(LeftRope.ActualWidth, LeftRope.ActualHeight);
    

    事实证明,如果不为 PathFigure 指定 StartPoint,它会自动关闭图形,即连接点集合中的最后一个点和第一个点。

    【讨论】:

      猜你喜欢
      • 2022-10-26
      • 2021-03-08
      • 2018-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-01
      • 1970-01-01
      • 2018-02-11
      相关资源
      最近更新 更多