Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 在关键帧处停止情节提要_Wpf_Storyboard_Keyframe - Fatal编程技术网

Wpf 在关键帧处停止情节提要

Wpf 在关键帧处停止情节提要,wpf,storyboard,keyframe,Wpf,Storyboard,Keyframe,我为我正在制作的某个游戏制作了一个骰子(用c#),它是一个用户控件,它使用一个故事板来依次显示多个图像(如幻灯片),因此看起来像一个滚动的3D骰子。问题是在特定关键帧处启动和停止它。使用Pause()和Resume()似乎是合乎逻辑的,但我不知道如何在精确的关键帧处暂停 有些人使用单独的分派器来执行此操作,但这不够精确,无法在关键帧处停止。(例如,如果抛出4,则必须在4图像上停止) 所以,如果有这样的方法就好了: TimeSpan keyTime = new TimeSpan(0,0,0,0,7

我为我正在制作的某个游戏制作了一个骰子(用c#),它是一个用户控件,它使用一个故事板来依次显示多个图像(如幻灯片),因此看起来像一个滚动的3D骰子。问题是在特定关键帧处启动和停止它。使用Pause()和Resume()似乎是合乎逻辑的,但我不知道如何在精确的关键帧处暂停

有些人使用单独的分派器来执行此操作,但这不够精确,无法在关键帧处停止。(例如,如果抛出4,则必须在4图像上停止)

所以,如果有这样的方法就好了:

TimeSpan keyTime = new TimeSpan(0,0,0,0,750); // 750 miliseconds
myStoryBoard.ResumeTo(keyTime); // <- doesn't exist as far as I know
TimeSpan-keyTime=新的TimeSpan(0,0,0,0750);//750毫秒
myStoryBoard.ResumeTo(按键时间);// 试试这个

我的例子是一个旋转箭头,我可以在指定的角度停止它

<Window.Resources>
    <Storyboard x:Key="Storyboard1">
        <DoubleAnimationUsingKeyFrames     
            Storyboard.TargetProperty="(UIElement.RenderTransform).
            (TransformGroup.Children)[2].(RotateTransform.Angle)" 
            Storyboard.TargetName="RightPanelButton1">
            <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0.0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:1" Value="45.0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:2" Value="90.0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:3" Value="135.0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:4" Value="180.0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Window.Resources>



Storyboard st = ((Storyboard)this.Resources["Storyboard1"]);

st.Begin();
st.Seek(new TimeSpan(0,0,2));
st.Pause();

Abbas Ahmed

故事板st=((故事板)this.Resources[“故事板1]”);
圣贝京();
st.Seek(新时间跨度(0,0,2));
圣帕斯();
阿巴斯·艾哈迈德

也许为每种情况编写动画会更容易?@MaratKhasanov这实际上可能是可行的,有36种情况,但由于您可以使用Seek()更改起始点,因此我需要6种。德克萨斯州!尽管我仍然想知道是否有一个合适的方法。你们最终找到了怎么做的方法了吗?@MichaelIV不,我没有,我用了MaratKhasanov的建议,制作了6个不同的动画。这不是我想要的,但它成功了。
<Window.Resources>
    <Storyboard x:Key="Storyboard1">
        <DoubleAnimationUsingKeyFrames     
            Storyboard.TargetProperty="(UIElement.RenderTransform).
            (TransformGroup.Children)[2].(RotateTransform.Angle)" 
            Storyboard.TargetName="RightPanelButton1">
            <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0.0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:1" Value="45.0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:2" Value="90.0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:3" Value="135.0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:4" Value="180.0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Window.Resources>



Storyboard st = ((Storyboard)this.Resources["Storyboard1"]);

st.Begin();
st.Seek(new TimeSpan(0,0,2));
st.Pause();

Abbas Ahmed