DoubleAnimation 创建动画问题

adonis_net adonis_net 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
步骤1:创建一个Rectangle.
代码:
//初始化bullet
private void bulletInit(string bulletType)
{

rect = new Rectangle();
var imageBrush = new ImageBrush();
imageBrush.Stretch = Stretch.None;
imageBrush.AlignmentX = AlignmentX.Left;
imageBrush.AlignmentY = AlignmentY.Top;
switch (bulletType)
{
case "green":
imageBrush.ImageSource = new BitmapImage(new Uri("/SLADdemo;component/" + bullet[0], UriKind.Relative));
break;
case "ice":
imageBrush.ImageSource = new BitmapImage(new Uri("/SLADdemo;component/" + bullet[1], UriKind.Relative));
break;
case "fire":
imageBrush.ImageSource = new BitmapImage(new Uri("/SLADdemo;component/" + bullet[2], UriKind.Relative));
break;
}

rect.Fill = imageBrush;
rect.Width = 47;
rect.Height = 47;
LayoutRoot.Children.Add(rect);
Canvas.SetLeft(rect, 150);
Canvas.SetTop(rect, 118);
rect.Visibility = System.Windows.Visibility.Collapsed;

}

步骤2:给矩形创建动画
代码:

//显示
rect.Visibility = System.Windows.Visibility.Visible;

//新建动画
storyboard = new Storyboard();




//创建X轴方向动画

DoubleAnimation da = new DoubleAnimation();


Duration dur = new Duration(TimeSpan.FromMilliseconds(1000));

da.Duration = dur;
da.From = Canvas.GetLeft(rect);
da.To = 800;

Storyboard.SetTarget(da, rect);

Storyboard.SetTargetProperty(da, new PropertyPath("(Canvas.Left)"));

storyboard.Children.Add(da);


//将动画动态加载进资源内

if (!Resources.Contains("rectAnimation"))
{

Resources.Add("rectAnimation", storyboard);


}

//动画播放

storyboard.Begin();


bulletInit("ice");



问题:动画能正常运行,但是运行过程中图像回时不时往回弹,不是很平滑,请问这是什么原因?
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
adonis_net
WPF/Silverlight 8,757 成员 12,031 内容