/// 创建动画
/// </summary>
private voID CreateStoryboard()
{
// 元素当前所在的坐标点
Point currentPoint = new Point(Canvas.Get@R_404_6823@(darkMoon), Canvas.Gettop(darkMoon));
// 目标点坐int标
Point point = new Point( 280 , - 245 );
// 创建动画容器时间线
Storyboard storyboard = new Storyboard();
DoubleAnimation doubleAnimation = new DoubleAnimation();
// 创建X轴方向动画
doubleAnimation.From = currentPoint.X;
doubleAnimation.To = point.X;
doubleAnimation.Duration = new Duration( new TimeSpan( 0 , 0 , 1 ));
Storyboard.SetTarget(doubleAnimation, darkMoon);
Storyboard.SetTargetProperty(doubleAnimation,
new PropertyPath( " (UIElement.Rendertransform).(transformGroup.Children)[3].(Translatetransform.X) " ));
storyboard.Children.Add(doubleAnimation);
// 创建Y轴方向动画
doubleAnimation = new DoubleAnimation();
doubleAnimation.SetValue(DoubleAnimation.FromProperty, currentPoint.Y);
doubleAnimation.SetValue(DoubleAnimation.toproperty, point.Y);
doubleAnimation.SetValue(DoubleAnimation.DurationProperty, new Duration( new TimeSpan( 0 , 1 )));
Storyboard.SetTarget(doubleAnimation,
new PropertyPath( " (UIElement.Rendertransform).(transformGroup.Children)[3].(Translatetransform.Y) " ));
storyboard.Children.Add(doubleAnimation);
storyboard.Begin();
} 下面再来一起学习一个稍微复杂点的二维向量运动,模拟屏幕内有一小球,当鼠标在舞台上点击则小球以动画的形式移动到鼠标点击处。如下XAML定义: < UserControl x:Class ="SLV.MainPage"
xmlns ="@R_419_6822@://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="@R_419_6822@://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d ="@R_419_6822@://schemas.microsoft.com/Expression/blend/2008"
xmlns:mc ="@R_419_6822@://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable ="d" >
< Canvas x:name ="LayoutRoot" WIDth ="400" Height ="400" Background ="Black" Mouse@R_404_6823@buttonDown ="OnMouseDown" >
< Ellipse Fill ="YellowGreen" x:name ="ellipse"
WIDth ="20"
Height ="20"
Canvas.@R_404_6823@ ="80"
Canvas.top ="66" >
</ Ellipse >
</ Canvas >
</ UserControl >
其舞台的鼠标左键点击事件代码如下: private voID OnMouseDown( object sender, System.windows.input.MousebuttonEventArgs e)
{ //鼠标点击点坐标
var mousePoint = e.Getposition(null);
//当前对象所在坐标
var currentPoint = new Point(( double )ellipse.GetValue(Canvas.@R_404_6823@Property), ( double )ellipse.GetValue(Canvas.topProperty));
Storyboard sb = new Storyboard();
//创建X坐标方向动画
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.From = currentPoint.X;
doubleAnimation.To = mousePoint.X;
doubleAnimation.Duration = new Duration( new TimeSpan( 0 , 2 ));
Storyboard.SetTarget(doubleAnimation, ellipse);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath( " (Canvas.@R_404_6823@) " ));
sb.Children.Add(doubleAnimation);
//创建Y坐标方向动画
doubleAnimation = new DoubleAnimation();
doubleAnimation.From = currentPoint.Y;
doubleAnimation.To = mousePoint.Y;
doubleAnimation.Duration = new Duration( new TimeSpan( 0 , new PropertyPath( " (Canvas.top) " ));
sb.Children.Add(doubleAnimation);
sb.Begin();
} 以上太阳的简单位置变换移动和小球随鼠标的移动都可以理解为平面中向量的运动,只不过在实现上没有直接通过向量的变换实现,而是通过Silverlight中提供的动画API实现,个人认为,从某种角度可以将Silverlight中的动画API理解为Silverlight的向量API,动画API实现的平面动画理解为向量运动。 推荐资源: MSDN: http://msdn.microsoft.com/zh-cn/library/cc189090(VS.95).aspx http://www.silverlight.net/learn/quickstarts/animations/ Silverlight & Blend动画设计系列文章 《Function Silverlight 3 Animation》----本篇中使用的部分素材选自此书 总结
以上是内存溢出为你收集整理的Silverlight & Blend动画设计系列十:Silverlight中的坐标系统(Coordinate System)与向量(Vector)运动全部内容,希望文章能够帮你解决Silverlight & Blend动画设计系列十:Silverlight中的坐标系统(Coordinate System)与向量(Vector)运动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)