WPF 做的动画

<Window x:Class="AnimationDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <DockPanel>
        <DockPanel.Triggers>
            <EventTrigger RoutedEvent="Button.Click" SourceName="buttonBeginMoveEyes">
                <BeginStoryboard x:Name="beginMoveEyes">
                    <Storyboard>
                        <DoubleAnimation RepeatBehavior="Forever" DecelerationRatio=".8"
                                         AutoReverse="True" By="6" Duration="0:0:1"
                                         Storyboard.TargetName="eyeLeft"
                                         Storyboard.TargetProperty="(Canvas.Left)"/>
                        <DoubleAnimation RepeatBehavior="Forever" AutoReverse="True"
                                         By="6" Duration="0:0:5" Storyboard.TargetName="eyeLeft"
                                         Storyboard.TargetProperty="(Canvas.Top)"/>
                        <DoubleAnimation RepeatBehavior="Forever" DecelerationRatio=".8"
                                         AutoReverse="True" By="-6" Duration="0:0:3"
                                         Storyboard.TargetName="eyeRight"
                                         Storyboard.TargetProperty="(Canvas.Left)"/>
                        <DoubleAnimation RepeatBehavior="Forever" AutoReverse="True"
                                         By="6" Duration="0:0:6" Storyboard.TargetName="eyeRight"
                                         Storyboard.TargetProperty="(Canvas.Top)"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="buttonStopMoveEyes">
                <StopStoryboard BeginStoryboardName="beginMoveEyes"/>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="buttonResize">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation RepeatBehavior="2" AutoReverse="True" Storyboard.TargetName="scale1"
                                         Storyboard.TargetProperty="(ScaleTransform.ScaleX)"
                                         From="0.1" To="3" Duration="0:0:5">
                            <DoubleAnimation.EasingFunction>
                                <ElasticEase/>
                            </DoubleAnimation.EasingFunction>    
                        </DoubleAnimation>
                        <DoubleAnimation RepeatBehavior="2" AutoReverse="True" Storyboard.TargetName="scale1"
                                         Storyboard.TargetProperty="(ScaleTransform.ScaleY)"
                                         From="0.1" To="3" Duration="0:0:5">
                            <DoubleAnimation.EasingFunction>
                                <ElasticEase/>
                            </DoubleAnimation.EasingFunction>
                            
                        </DoubleAnimation>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </DockPanel.Triggers>
        <StackPanel Orientation="Vertical" DockPanel.Dock="Top">
            <Button x:Name="buttonBeginMoveEyes" Content="Start Move Eyes" Margin="5"/>
            <Button x:Name="buttonStopMoveEyes" Content="Stop Move Eyes" Margin="5"/>
            <Button x:Name="buttonResize" Content="Resize" Margin="5"/>
        </StackPanel>
        <Canvas>
            <Canvas.LayoutTransform>
                <ScaleTransform ScaleX="1" ScaleY="1" x:Name="scale1"/>
            </Canvas.LayoutTransform>
            <Ellipse Canvas.Left="10" Canvas.Top="10" Width="100" Height="100" Stroke="Blue" StrokeThickness="4" Fill="Yellow"/>
            <Ellipse Canvas.Left="30" Canvas.Top="12" Width="60" Height="30">
                <Ellipse.Fill>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <GradientStop Offset="0.1" Color="DarkGreen"/>
                        <GradientStop Offset="0.7" Color="Transparent"/>
                    </LinearGradientBrush>
                </Ellipse.Fill>
            </Ellipse>
            <Ellipse Canvas.Left="30" Canvas.Top="35" Width="25" Height="20" Stroke="Blue" StrokeThickness="3" Fill="White"/>
            <Ellipse x:Name="eyeLeft" Canvas.Left="40" Canvas.Top="43" Width="6" Height="5" Fill="Black"/>
            <Ellipse Canvas.Left="65" Canvas.Top="35" Width="25" Height="20" Stroke="Blue" StrokeThickness="3" Fill="White"/>
            <Ellipse x:Name="eyeRight" Canvas.Left="75" Canvas.Top="43" Width="6" Height="5" Fill="Black"/>
            <Path Name="mouth" Stroke="Blue" StrokeThickness="4" Data="M 40,74 Q 57,95 80,74"/>
        </Canvas>
    </DockPanel>
</Window>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C#运用WPF实现游戏动画制作 从QXGame(WPF GAME ENGINE)游戏引擎公布以来,受到很多朋友的热切关注,于是乎有了写教程的想法。那么从今天开始,我将带领大家一步一步的学会如何使用纯C#开发WPF/Silverlight游戏引擎,过程中我会尽量的开源,并对相关小技巧进行解释和介绍,比较复杂的算法原理我会给大家一条绝对可行的思路,这里只想客观的告诉读者下面两点: 一、WPF开发的是桌面应用程序,自包括Vista在内以后的Windows系列操作系统均大量以之为主流图形工具,即将全面取代Winform,并且Windows 7将集成.NET3.5+框架,在当今Windows系列操作系统占据90%同类市场的现状下,这意味着什么呢? 二、Silverlight基于一个约4M左右的MINI型.NET框架,目前版本2.0,3.0的beta英文版,从发展趋势看是绝对有与Flash抗衡并且在未来超越它的可能性。Silverlight的优势更表现在它可以用一切.NET语言例如C#,VB.NET,C++.NET等开发,拓展度与可以参与开发的人群远远高于只能用AS开发的FLASH。 转入正题,网上已经有很多关于如何创建WPF/Silverlight动画的教程,但是均为使用Blend工具制作,或直接写在xaml代码内的动画,这样往往造成很多朋友误以为其实WPF/Silverlight不就是MS的Flash?诚然,如果您真的像那些教程里说的去开发WPF/Silverlight程序,我个人觉得一点意义都没有。这样开发出来的东西根本就超越不了Flash,那何苦还要投入如此多的精力来学习它? 所以本系列教程将全方位的以纯C#程序语言进行动态创建一切可视化对象,从而构建出一个如QXGame(WPF GAME ENGINE)游戏引擎,这才是我本系列教程希望达到的目的。 (注:本教程使用的开发工具为Visual studio 2008 版本sp1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值