2011-10-07 55 views
2

我正在製作Silverlight程序,用戶可以將蠕蟲添加到地面。蠕蟲必須修改。他們可以有三個或更多的控制點,從用戶可以移動和編輯蠕蟲。蠕蟲必須有最大和最小長度。還有一些看起來像蠕蟲的服裝。我用規範樣條做了相當好的蠕蟲,但問題是最大長度和最小長度以及裝備。我不是在等待任何準備好的代碼,但有些新的想法是如何做到的。如何製作可修改的蠕蟲(形狀)?

例由MSPAINT做出:) http://tinypic.com/r/bgxp3m/7

+0

+1問蠕蟲。 –

回答

1

您可以在Expression Blend中使用鋼筆工具創建貝塞爾曲線的開放路徑。然後,直接選擇工具可以修改點以給出所需的形狀。如果您在Storyboard中執行此操作,則Expression Blend會將Path數據展開爲未壓縮格式,該格式可以通過後臺代碼進行動畫,命名和引用。這裏是一個蠕蟲示例:

<Grid x:Name="LayoutRoot" Background="White"> 
    <Grid.Resources> 
     <Storyboard x:Name="wriggle"> 
      <PointAnimation Duration="0:0:0.7" To="59.4217224121094,11.1413049697876" Storyboard.TargetProperty="(Path.Data).(PathGeometry.Figures)[0].(PathFigure.Segments)[1].(BezierSegment.Point1)" Storyboard.TargetName="wormBody" d:IsOptimized="True"/> 
      <PointAnimation Duration="0:0:0.7" To="21.5,45.9078826904297" Storyboard.TargetProperty="(Path.Data).(PathGeometry.Figures)[0].(PathFigure.Segments)[0].(BezierSegment.Point2)" Storyboard.TargetName="wormBody" d:IsOptimized="True"/> 
      <PointAnimation Duration="0:0:0.7" To="9.25,28.6580047607422" Storyboard.TargetProperty="(Path.Data).(PathGeometry.Figures)[0].(PathFigure.Segments)[0].(BezierSegment.Point1)" Storyboard.TargetName="wormBody" d:IsOptimized="True"/> 
     </Storyboard> 
    </Grid.Resources> 
    <Path x:Name="wormBody" HorizontalAlignment="Left" Height="67.316" Margin="167,150.092,0,0" Stroke="Black" StrokeThickness="10" UseLayoutRounding="False" VerticalAlignment="Top" Width="91"> 
     <Path.Data> 
      <PathGeometry FillRule="EvenOdd"> 
       <PathFigure IsFilled="True" IsClosed="False" StartPoint="5,62.3157653808594"> 
        <BezierSegment Point3="42.2093734741211,24.9581699371338" Point2="4.49375009536743,30.3548755645752" Point1="35.375,53.3601760864258"/> 
        <BezierSegment Point3="86,5" Point2="73.8499984741211,24.9581699371338" Point1="54.1062507629395,22.6553039550781"/> 
       </PathFigure> 
      </PathGeometry> 
     </Path.Data> 
    </Path> 
    <Ellipse HorizontalAlignment="Left" Height="15" Margin="246,146,0,0" Stroke="Black" StrokeThickness="10" VerticalAlignment="Top" Width="15"/> 
</Grid> 
+0

+1,這太棒了! –