使用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 :(得分: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;