8,756
社区成员




//初始化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;
}
//显示
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");