110,537
社区成员
发帖
与我相关
我的任务
分享
public void GO(string key)
{
if (!this.AlloweKeys.Contains(key) || key == KeyEnum.K.ToString())
{
return;
}
//记录精灵位置
this.Direction = key;
//改变精灵方向
this.Directions(key);
double to = 0;
Storyboard storyboard = new Storyboard();
if (key == KeyEnum.A.ToString() || key == KeyEnum.D.ToString())
{
to = GetMove(key);
//设置左右移动多少
DoubleAnimation xAnimation = new DoubleAnimation()
{
To = to,
Duration = new Duration(TimeSpan.FromMilliseconds(this.DoTime))
};
Storyboard.SetTarget(xAnimation, this);
Storyboard.SetTargetProperty(xAnimation, new PropertyPath("(Canvas.Left)"));
storyboard.Children.Add(xAnimation);
}
if (key == KeyEnum.S.ToString() || key == KeyEnum.W.ToString())
{
to = GetMove(key);
//设置上下移动多少
DoubleAnimation yAnimation = new DoubleAnimation()
{
To = to,
Duration = new Duration(TimeSpan.FromMilliseconds(this.DoTime))
};
Storyboard.SetTarget(yAnimation, this);
Storyboard.SetTargetProperty(yAnimation, new PropertyPath("(Canvas.Top)"));
storyboard.Children.Add(yAnimation);
}
if (to >= 420 || to <= 0)
{
return;
}
//开始移动
storyboard.Begin();
}