2009-08-18 94 views
3

问候!如何动画多边形? (阅读:动画轮廓改变形状)

我目前正在开发一个Silverlight项目,我想动画一个简单的多边形形状(实际上是一个梯形)。具体来说,我想在事件发生后动态调整四点中的两点。我需要/想要调整大小并将其中一个平行边移动到另一个位置。

我承认我对Silverlight来说比较新,而且还没有找到可以告诉我的来源,甚至有可能,更不用说它是如何实现的。

我之前使用过动画,所以故事板和动画的一般概念对我来说并不陌生。但是,如何在动画中移动多边形的点?是否有替代品具有类似的光学效果(例如制作路径)?
是否有一个的PropertyPath我可以使用,类似于

P3AnimBack.SetValue(Storyboard.TargetPropertyProperty, 
    new PropertyPath("(Path.Data). 
     (PathGeometry.Figures)[0].(PathFigure.Segments)[0]. 
     (BezierSegment.Point3)")); 

,如在Point Animation in Silverlight 3 tutorial发现了什么?

谢谢大家提前。 :)

回答

4

我不知道有关Silverlight的东西,或者在一般的.NET动画,但Charles Petzold没有类似的东西:

+0

哇,这很快。喜欢这个网站。 :) 感谢您的快速回复。 该代码很容易适应多边形而不是折线 - 并且或多或少地完全符合我的要求。 – Cornelius 2009-08-18 14:44:09

+0

那么upvote怎么样,呵呵呵? :) – 2009-08-18 14:55:39

+0

...你去^。^再次感谢 – Cornelius 2009-08-19 12:25:06

1

按照评论中的要求,我解释了我最终用来制作我的动物重刑:

我依靠Animated Polyline Interpolations in Silverlight和或多或少直接使用此代码 - “窃取”PointCollectionInterpolator.cs类。

然后,我有我的方法来创建我需要的多边形,并准备动画:

private void CreatePolygon(TextBox txtbx, string prop, Color curcol) 
    { 
     PointCollectionInterpolator pci = new PointCollectionInterpolator(); 
     pci.Points1 = new PointCollection() // Start Points 
      { 
       new Point(...), 
       new Point(...), 
       new Point(...), 
       new Point(...), 
      }; 

     pci.Points2 = new PointCollection() // End Points 
      { 
       new Point(...), 
       new Point(...), 
       new Point(...), 
       new Point(...), 
      }; 

     Polygon tmpply = new Polygon(); 
     LayoutRoot.Children.Add(tmpply); 

     tmpply.Points = pci.InterpolatedPoints; 

     DoubleAnimation animpci = new DoubleAnimation(); 
     animpci.Duration = someDuration; 
     animpci.From = 0.0; 
     animpci.To = 1.0; 
     Storyboard.SetTarget(animpci, pci); 
     Storyboard.SetTargetProperty(animpci, new PropertyPath("(Progress)")); 
     myStoryBoard.Children.Add(animpci); 
    } 

然后在一些随机事件处理,我开始动画。另外,所以我可以重复使用该方法,将端点集合移动到起点集合中,并用新的端点更新插补器。 (记住设置进度为0.0 ...)因此,每当处理程序触发时,多边形将无缝地变形为新的。

private void SomeEventHandler(object sender, RoutedEventArgs e) 
{ 
    PointCollectionInterpolator polygonPCI = 
      this.referenceToPointCollectionInterpolator; 
    polygonPCI.Points1 = polygonPCI.Points2; 
    polygonPCI.Progress = 0.0; 
    polygonPCI.Points2 = getNewEndPoints(); 
    myStoryBoard.Begin(); 
} 

回想起来,我将名称从Points1和Points2更改为StartPoints和EndPoints resp。 希望这有助于。 :)