2012-12-26 93 views
3

这里是什么样子: http://screencast.com/t/4cd1yQJReXtWPF动画沿着正确的路径,但它关在空间

的小船图像是假设跟着你出去图表为它的路径。它确实有效 - 它遵循路径,但是它从错误的地方开始。我无法弄清楚我的动画有什么问题,而且我现在已经多次阅读了代码。应用程序的XAML是非常简单的都是含有内 帆布NAME =“Canvas1”背景中的元素=“黑”

,这画布是 窗口

及以下的子元素是代码,做动画。我知道一个事实,即我喂它的线是正确的。这只是他们的参考点被搞砸了。它应该是Canvas1,但它不是。

  NameScope.SetNameScope(this, new NameScope()); 

      MatrixTransform buttonMatrixTransform = new MatrixTransform(); 
      ship1.RenderTransform = buttonMatrixTransform; 

      this.RegisterName("ButtonMatrixTransform", buttonMatrixTransform); 

      PathGeometry animationPath = new PathGeometry(); 
      PathFigure pFigure = new PathFigure(); 
      pFigure.StartPoint = new Point(pathnodes.ElementAt<Line>(0).X1, pathnodes.ElementAt<Line>(0).Y1); 

      PolyLineSegment ls = new PolyLineSegment(); 

      foreach (Line l in pathnodes) 
      { 
       ls.Points.Add(new Point(l.X1, l.Y1)); 
       ls.Points.Add(new Point(l.X2, l.Y2)); 
      } 

      pFigure.Segments.Add(ls);  
      animationPath.Figures.Add(pFigure); 

      animationPath.Freeze(); 

      MatrixAnimationUsingPath matrixAnimation = 
       new MatrixAnimationUsingPath(); 

      matrixAnimation.IsOffsetCumulative = false; 

      matrixAnimation.PathGeometry = animationPath; 
      matrixAnimation.Duration = TimeSpan.FromSeconds(5); 
      matrixAnimation.DoesRotateWithTangent = true; 

      Storyboard.SetTargetName(matrixAnimation, "ButtonMatrixTransform"); 
      Storyboard.SetTargetProperty(matrixAnimation, 
       new PropertyPath(MatrixTransform.MatrixProperty)); 

      Storyboard pathAnimationStoryboard = new Storyboard(); 
      pathAnimationStoryboard.Children.Add(matrixAnimation); 

      pathAnimationStoryboard.Begin(this); 

谢谢!

回答

0

我看不到你的视频:O(但是,它可能与RenderTransformOrigin没有设置吗?通常当我进行转换时,我将RTO设置为0.5,0.5,以便原点位于物体的中心。