2012-03-01 5 views
3

저는 WPF와 C# .NET에서 룰렛 게임을 만들고 있습니다. 나는 바퀴를 성공적으로 돌린다. 그러나 나는 공이 멈추고있는 특정한 가치를 얻기 위해 붙어있다.룰렛 휠의 특정 번호에서 공을 멈추는 법

아무도 내가 내가 볼이 정지되는 값을 얻을 수있는 방법 Expression Blend를 (아래 코드)를 사용하여 기본 애니메이션을 만들었습니다 중 하나

의 값을 얻기 위해 적용 할 수있는 논리의 종류 나에게 도움이 될 수 있습니다.

<Window 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
x:Class="demo.MainWindow" 
x:Name="Window" 
Title="MainWindow" 
Width="640" Height="480"> 
<Window.Resources> 
    <Storyboard x:Key="spinWheel"> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="canvas"> 
      <EasingDoubleKeyFrame KeyTime="0" Value="-0.056"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1" Value="-89.871"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2" Value="-179.468"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:3" Value="-269.405"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:4" Value="-360.488"/> 
     </DoubleAnimationUsingKeyFrames> 
     <DoubleAnimationUsingPath Duration="0:0:3.96" Source="X" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="ellipse"> 
      <DoubleAnimationUsingPath.PathGeometry> 
       <PathGeometry Figures="M39.5,115 C39.5,218.55339 -44.446609,302.5 -148,302.5 C-251.55339,302.5 -335.5,218.55339 -335.5,115 C-335.5,11.446609 -251.55339,-72.5 -148,-72.5 C-44.446609,-72.5 39.5,11.446609 39.5,115 z"/> 
      </DoubleAnimationUsingPath.PathGeometry> 
     </DoubleAnimationUsingPath> 
     <DoubleAnimationUsingPath Duration="0:0:3.96" Source="Y" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="ellipse"> 
      <DoubleAnimationUsingPath.PathGeometry> 
       <PathGeometry Figures="M39.5,115 C39.5,218.55339 -44.446609,302.5 -148,302.5 C-251.55339,302.5 -335.5,218.55339 -335.5,115 C-335.5,11.446609 -251.55339,-72.5 -148,-72.5 C-44.446609,-72.5 39.5,11.446609 39.5,115 z"/> 
      </DoubleAnimationUsingPath.PathGeometry> 
     </DoubleAnimationUsingPath> 
    </Storyboard> 
</Window.Resources> 
<Window.Triggers> 
    <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
     <BeginStoryboard Storyboard="{StaticResource spinWheel}"/> 
    </EventTrigger> 
</Window.Triggers> 

<Grid x:Name="LayoutRoot"> 
    <Canvas x:Name="canvas" Margin="22,62,248,26" RenderTransformOrigin="0.5,0.5"> 
     <Canvas.RenderTransform> 
      <TransformGroup> 
       <ScaleTransform/> 
       <SkewTransform/> 
       <RotateTransform/> 
       <TranslateTransform/> 
      </TransformGroup> 
     </Canvas.RenderTransform> 
     <Ellipse x:Name="ellipse1" Fill="#FFF4F4F5" Stroke="Black" Height="354" Width="354"/> 
     <Path Data="M308,44 L308,394.5" Fill="#FFF4F4F5" Stretch="Fill" Stroke="Black" Width="1" Height="351.5" Canvas.Left="179" Canvas.Top="1"/> 
     <Path Data="M144,240 L495.5,240" Fill="#FFF4F4F5" Height="1" Stretch="Fill" Stroke="Black" Canvas.Left="1" Canvas.Top="176.5" Width="352.5"/> 
     <TextBlock x:Name="one" Height="88" TextWrapping="Wrap" Text="1" Width="72" FontSize="64" Canvas.Left="75" Canvas.Top="64.5"/> 
     <TextBlock x:Name="two" Height="88" TextWrapping="Wrap" Text="2" Width="72" FontSize="64" Canvas.Left="219" Canvas.Top="64.5"/> 
     <TextBlock x:Name="three" Height="88" TextWrapping="Wrap" Text="3" Width="72" FontSize="64" Canvas.Left="219" Canvas.Top="200.5"/> 
     <TextBlock x:Name="four" Height="88" TextWrapping="Wrap" Text="4" Width="72" FontSize="64" Canvas.Left="75" Canvas.Top="200.5"/> 
    </Canvas> 
    <Ellipse x:Name="ellipse" Fill="#FFFF2300" HorizontalAlignment="Right" Height="24" Margin="0,112,264,0" Stroke="Black" VerticalAlignment="Top" Width="24" RenderTransformOrigin="0.5,0.5"> 
     <Ellipse.RenderTransform> 
      <TransformGroup> 
       <ScaleTransform/> 
       <SkewTransform/> 
       <RotateTransform/> 
       <TranslateTransform/> 
      </TransformGroup> 
     </Ellipse.RenderTransform> 
    </Ellipse> 
</Grid> 

+4

다른 방법으로 생각하니? 목표 수를 계산하고 거기에 도착한 공의 시각화를 처리하십시오. – Morothar

+1

@Morothar, 그 자체로 대답이 아니어도 답장으로 게시 된 경우 +1 (+1)이라고 표시합니다. –

+0

@Morothar @Morothar 그 생각은했지만 여전히 비슷한 문제가 있습니다. 특정 위치에서 볼을 멈추는 법 – avinnash2515

답변

0

코드에서

<RotateTransform x:Name="wheelAngle" /> 

변환

<Storyboard x:Key="spinWheel" Completed="Storyboard_Completed"> 

당신의 회전에 이름을 추가하여 스토리 보드에 이벤트 처리기를 추가 뒤에 약간의 수학은 어디에 공을 밖으로 작동합니까 wheelAngle.AngleballAngle.Angle입니다.

관련 문제