WPF 实现加速小火箭~
生活随笔
收集整理的這篇文章主要介紹了
WPF 实现加速小火箭~
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
WPF開發者QQ群:?340500857
?? ??? 由于微信群人數太多入群請添加小編微信號
?yanjinhuawechat 或 W_Feng_aiQ?邀請入群
?需備注WPF開發者?
? PS:有更好的方式歡迎推薦。
01
—
代碼如下
一、創建?SpeedRocketsExample.xaml 代碼如下。
<Window?x:Class="WPFDevelopers.Samples.ExampleViews.SpeedRocketsMini"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews"xmlns:sys="clr-namespace:System;assembly=mscorlib"mc:Ignorable="d"?WindowStyle="None"?ShowInTaskbar="False"WindowState="Maximized"?Background="Transparent"ResizeMode="NoResize"?AllowsTransparency="True"Height="450"?Width="800"?MaxHeight="{x:Static?SystemParameters.MaximizedPrimaryScreenHeight}"><Window.Resources><local:ActualHeightConverters?x:Key="actualHeightConverters"/></Window.Resources><Grid><Button?Style="{StaticResource?PrimaryButton}"?Content="X"?Width="60"?Height="40"?VerticalAlignment="Top"?HorizontalAlignment="Right"Click="Button_Click"/><Grid?VerticalAlignment="Bottom"HorizontalAlignment="Right"Margin="0,0,0,40"><Grid.Resources><Storyboard?x:Key="StoryboardMouseDown"><DoubleAnimation?Storyboard.TargetName="rotate_y"?To="0"?Duration="0:0:0"Storyboard.TargetProperty="Angle"/><DoubleAnimation?Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"Storyboard.TargetName="PART_Viewport3D"Duration="0:0:2"?From="0"?To="{Binding?RelativeSource={RelativeSource?AncestorType={x:Type?Window},Mode=FindAncestor},?Path=ActualHeight,Converter={StaticResource?actualHeightConverters}}"?EasingFunction="{StaticResource?BackEaseEaseInOut}"/><RectAnimation?Storyboard.TargetProperty="(Ellipse.Clip).(RectangleGeometry.Rect)"Storyboard.TargetName="Ellipse3"BeginTime="0:0:.5"?To="0,80,100,100"Duration="0:0:2"?From="0,10,100,100"?AutoReverse="True"></RectAnimation><StringAnimationUsingKeyFrames?Storyboard.TargetName="TextBlock1"?Storyboard.TargetProperty="Text"BeginTime="0:0:.5"?AutoReverse="True"><DiscreteStringKeyFrame?Value="90"???KeyTime="0:0:0"/><DiscreteStringKeyFrame?Value="85"???KeyTime="0:0:.30"?/><DiscreteStringKeyFrame?Value="70"???KeyTime="0:0:1"?/><DiscreteStringKeyFrame?Value="40"???KeyTime="0:0:1.5"?/><DiscreteStringKeyFrame?Value="10"???KeyTime="0:0:2"?/></StringAnimationUsingKeyFrames><DoubleAnimation?Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"Storyboard.TargetName="PART_Viewport3D"Duration="0:0:0"?BeginTime="0:0:2"To="0"/></Storyboard><Storyboard??x:Key="StoryboardMouseEnter"><DoubleAnimation?Duration="00:00:.5"?BeginTime="00:00:0"From="0"Storyboard.TargetName="PART_Viewport3D"Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleX)"To="1"/><DoubleAnimation?Duration="00:00:.5"?BeginTime="00:00:0"From="0"Storyboard.TargetName="PART_Viewport3D"Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleY)"To="1"?/><DoubleAnimation?Storyboard.TargetName="rotate_y"?From="0"?To="360"BeginTime="00:00:.5"?Storyboard.TargetProperty="Angle"Duration="0:0:1.5"?RepeatBehavior="Forever"?/></Storyboard><Storyboard?x:Key="StoryboardMouseLeave"><DoubleAnimation?Duration="00:00:0"?To="0"?Storyboard.TargetProperty="Angle"?Storyboard.TargetName="rotate_y"?/><DoubleAnimation?Duration="00:00:0"?From="1"Storyboard.TargetName="PART_Viewport3D"Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleX)"To="0"/><DoubleAnimation?Duration="00:00:0"?From="1"Storyboard.TargetName="PART_Viewport3D"Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleY)"To="0"?/></Storyboard></Grid.Resources><Grid?Height="100"?Width="100"?ToolTip="按下加速~喵?(゜-゜)つロ?"><Ellipse??Fill="White"?Stroke="#FFAEABAB"?StrokeThickness="1"></Ellipse><Ellipse??Fill="#FF5F9E74"?Margin="4"></Ellipse><Ellipse??Fill="#FF6BCF77"?Margin="8"?x:Name="Ellipse3"><Ellipse.Clip><RectangleGeometry?Rect="0,10,100,100"></RectangleGeometry></Ellipse.Clip></Ellipse><WrapPanel??HorizontalAlignment="Center"?VerticalAlignment="Center"><TextBlock?Foreground="White"FontSize="30"FontWeight="Bold"?FontFamily="Agency?FB"Text="90"x:Name="TextBlock1"></TextBlock><TextBlock?Foreground="White"FontSize="30"Text="%"FontWeight="Bold"?FontFamily="Agency?FB"></TextBlock></WrapPanel><Grid.Triggers><EventTrigger?RoutedEvent="MouseDown"><BeginStoryboard?Storyboard="{StaticResource?StoryboardMouseDown}"/></EventTrigger><EventTrigger?RoutedEvent="MouseEnter"><BeginStoryboard?Storyboard="{StaticResource?StoryboardMouseEnter}"/></EventTrigger><EventTrigger?RoutedEvent="MouseLeave"><BeginStoryboard?Storyboard="{StaticResource?StoryboardMouseLeave}"/></EventTrigger></Grid.Triggers></Grid><!--<Ellipse?Height="80"?Width="80"?x:Name="Ellipse1"StrokeThickness="2"?Stroke="{StaticResource?PrimaryNormalSolidColorBrush}"ToolTip="按下加速~喵?(゜-゜)つロ?"><Ellipse.Fill><LinearGradientBrush?EndPoint="0.5,1"?StartPoint="0.5,0"><GradientStop?Color="#FFF7D1A3"/><GradientStop?Color="#FFF98C0C"?Offset="1"/><GradientStop?Color="#FFF49F39"?Offset="0.5"/></LinearGradientBrush></Ellipse.Fill><Ellipse.Triggers><EventTrigger?RoutedEvent="MouseDown"><BeginStoryboard?Storyboard="{StaticResource?StoryboardY}"/></EventTrigger><EventTrigger?RoutedEvent="MouseEnter"><BeginStoryboard?Storyboard="{StaticResource?StoryboardAngleY}"/></EventTrigger><EventTrigger?RoutedEvent="MouseLeave"><BeginStoryboard?Storyboard="{StaticResource?StoryboardNormal}"/></EventTrigger></Ellipse.Triggers></Ellipse>--><Viewport3D?Width="60"?Height="60"RenderTransformOrigin=".5,.5"x:Name="PART_Viewport3D"IsHitTestVisible="False"><Viewport3D.RenderTransform><TransformGroup><TranslateTransform?Y="0"/><ScaleTransform?ScaleX="0"?ScaleY="0"/></TransformGroup></Viewport3D.RenderTransform><!--<Viewport3D.Triggers><EventTrigger?RoutedEvent="Viewport3D.MouseDown"><BeginStoryboard><Storyboard><DoubleAnimation?Storyboard.TargetName="rotate_y"? To="0"?Duration="0:0:0" Storyboard.TargetProperty="Angle"/><DoubleAnimation?Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TranslateTransform.Y)"Duration="0:0:1"To="{Binding?RelativeSource={RelativeSource?AncestorType={x:Type?Window},Mode=FindAncestor},?Path=ActualHeight,Converter={StaticResource?actualHeightConverters}}"?EasingFunction="{StaticResource?BackEaseEaseInOut}"/></Storyboard></BeginStoryboard></EventTrigger><EventTrigger?RoutedEvent="Viewport3D.MouseEnter"><BeginStoryboard><Storyboard?TargetProperty="Angle"><DoubleAnimation?Storyboard.TargetName="rotate_y"?From="0"?To="360"?Duration="0:0:1.5"?RepeatBehavior="Forever"?/></Storyboard></BeginStoryboard></EventTrigger><EventTrigger?RoutedEvent="MouseLeave"><BeginStoryboard><Storyboard?Storyboard.TargetProperty="Angle"?Storyboard.TargetName="rotate_y"><DoubleAnimation?Duration="00:00:0"?To="0"?/></Storyboard></BeginStoryboard></EventTrigger></Viewport3D.Triggers>--><Viewport3D.Camera><OrthographicCamera?LookDirection="0,0,-50"?Position="0,0,50"?UpDirection="0,1,0"/></Viewport3D.Camera><Viewport3D.Children><ModelVisual3D><ModelVisual3D.Content><AmbientLight?Color="Transparent"/></ModelVisual3D.Content></ModelVisual3D><ContainerUIElement3D><Viewport2DVisual3D><Viewport2DVisual3D.Geometry><MeshGeometry3D?Positions="-1,1,1?-1,-1,1?1,-1,1?1,1,1"?TriangleIndices="0?1?2?0?2?3"?TextureCoordinates="0,0?0,1?1,1?1,0"/></Viewport2DVisual3D.Geometry><Viewport2DVisual3D.Material><DiffuseMaterial?Viewport2DVisual3D.IsVisualHostMaterial="True"/></Viewport2DVisual3D.Material><Image?Source="/Images/SpeedRockets/飛機.png"/></Viewport2DVisual3D><Viewport2DVisual3D><Viewport2DVisual3D.Material><DiffuseMaterial?Viewport2DVisual3D.IsVisualHostMaterial="True"/></Viewport2DVisual3D.Material><Viewport2DVisual3D.Geometry><MeshGeometry3D?Positions="1,1,1?1,-1,1?-1,-1,1?-1,1,1" TextureCoordinates="0,0?0,1?1,1?1,0" TriangleIndices="0?1?2?0?2?3"/></Viewport2DVisual3D.Geometry><Image?Source="/Images/SpeedRockets/飛機.png"/></Viewport2DVisual3D><ContainerUIElement3D.Transform><Transform3DGroup><RotateTransform3D?CenterX="0"?CenterY="0"?CenterZ="1"><RotateTransform3D.Rotation><AxisAngleRotation3D?x:Name="rotate_y"?Axis="0?1?0"?/></RotateTransform3D.Rotation></RotateTransform3D></Transform3DGroup></ContainerUIElement3D.Transform></ContainerUIElement3D></Viewport3D.Children></Viewport3D></Grid></Grid> </Window>二、SnowCanvas.xamlSpeedRocketsExample.xaml.cs?代碼如下
using?System; using?System.Windows; using?System.Windows.Data;namespace?WPFDevelopers.Samples.ExampleViews {///?<summary>///?SpeedRocketsMini.xaml?的交互邏輯///?</summary>public?partial?class?SpeedRocketsMini?:?Window{public?SpeedRocketsMini(){InitializeComponent();}private?void?Button_Click(object?sender,?RoutedEventArgs?e){Close();}}public?class?ActualHeightConverters?:?IValueConverter{public?object?Convert(object?value,?Type?targetType,?object?parameter,?System.Globalization.CultureInfo?culture){return?0?-?(double)value;}public?object?ConvertBack(object?value,?Type?targetType,?object?parameter,?System.Globalization.CultureInfo?culture){return?null;}} }02
—
效果預覽
鳴謝素材提供者 -?王路飛
源碼地址如下
Github:https://github.com/WPFDevelopersOrg
Gitee:https://gitee.com/WPFDevelopersOrg
WPF開發者QQ群:?340500857?
Github:https://github.com/WPFDevelopersOrg
出處:https://www.cnblogs.com/yanjinhua
版權:本作品采用「署名-非商業性使用-相同方式共享 4.0 國際」許可協議進行許可。
轉載請著名作者 出處 https://github.com/WPFDevelopersOrg
掃一掃關注我們,
更多知識早知道!
點擊閱讀原文可跳轉至源代碼
總結
以上是生活随笔為你收集整理的WPF 实现加速小火箭~的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【.NET 遇上 GraphQL】 Ch
- 下一篇: 如何使用 C# 压缩单个文件?