动画AutoReverse = false,但无论如何都会这样做,并且从错误的起点开始

本文关键字:错误 这样做 起点 开始 AutoReverse false 无论如何 动画 | 更新日期: 2023-09-27 18:09:05

我试图从画布的右下角到画布的左上角获得图像,并永远重复这种行为。图像不应该做从左上角到右上角的反向动画。我是动画新手,所以我用了这个例子。

此刻,我的图像正在从左上角移动到右下角,然后返回。我尝试改变画布中图像的起始位置,结果,动画使用这个位置作为新的起点。我还尝试使用负值,让图像移动到相反的方向。减少片段中的点数可以缩短动画路径,但仅此而已。我还设置了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上开发一个桌面应用程序。

动画AutoReverse = false,但无论如何都会这样做,并且从错误的起点开始

你应该替换行:

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

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

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

相关文章: