2012-03-26 93 views
0

使用Silverlight和Storyboard,如何让两个物体以相同的速度行进不同的距离?现在,为了使我的控件动画化,我使用下面的代码。但是,如果一个控制器必须传送100个像素,另一个控制1000个像素,则动画不会以相同的速度运行。具有100像素行进距离的那个要慢得多。这是由于动画的持续时间,但我必须设置它,如果我想动画运行。如何让两个物体以相同的速度行进不同距离?

有没有另外一种方法来做到这一点,并确保无论控制器行驶的距离是多少,运动的速度是一样的?

var easefall = new QuadraticEase(); 
easefall.EasingMode = EasingMode.EaseIn; 

Storyboard storyboard = new Storyboard(); 
var animation = new DoubleAnimation(); 
animation.To = // 10, 50, 100... 
animation.Duration = TimeSpan.FromSeconds(0.50); 
animation.EasingFunction = easefall; 
+0

我假设你想要较短距离的物品前往完成其动画?如果不是,我想我们必须引用相对论。 – 2012-03-26 13:39:42

+0

如果你想恒定速度,你需要增加与距离成正比的持续时间。 – CodesInChaos 2012-03-26 14:18:58

+0

@CodeInChaos我明白,但我希望Silverlight能为我做这件事。我不想让时间成为一个常数,我想要速度。 – Martin 2012-03-26 14:28:06

回答

1

正如CodeInChaos提到的,你可能需要为了使您的旅行速率常数增加一个或两个变量,但无论这应该工作旅行的距离。

double rate = 0.05; //speed per unit of one change 
double duration = distance * rate; //i'll assume your distance is an input from somewhere 

var easefall = new QuadraticEase(); 
easefall.EasingMode = EasingMode.EaseIn; 

Storyboard storyboard = new Storyboard(); 
var animation = new DoubleAnimation(); 
animation.To = // 10, 50, 100... 
animation.Duration = TimeSpan.FromSeconds(duration); 
animation.EasingFunction = easefall; 
相关问题