public void Move(double left, double top) { void MoveAnimation(double value, DependencyProperty property, Action <UIElement, double> setter) { MoveStarted?.Invoke(this, EventArgs.Empty); var anim = new DoubleAnimation(value, new Duration(TimeSpan.FromSeconds(0.5))) { FillBehavior = FillBehavior.Stop }; anim.Completed += (sender, args) => { setter(this, value); Moved?.Invoke(this, args); }; BeginAnimation(property, anim); } if (Math.Abs(Canvas.GetLeft(this) - left) > double.Epsilon) { MoveAnimation(left, Canvas.LeftProperty, Canvas.SetLeft); } if (Math.Abs(Canvas.GetTop(this) - top) > double.Epsilon) { MoveAnimation(top, Canvas.TopProperty, Canvas.SetTop); } }
public void OnDragStart(MouseEventArgs e) { if (Enabled && !Moving) { if (DragBounds.Contains(e.Position) && MovementEnabled) { Moving = true; Position += e.DistanceMoved; MoveStarted?.Invoke(this, e); } } }
public virtual void OnMoveStarted(Action onMoveEnded) { MoveStarted?.Invoke(); PreviousPosition = CurrentPosition; IsMoving = true; LayerManager.Instance.CurrentLayer?.RefreshPlayerPossibleMoves(); moveEndedCallback = onMoveEnded; if (anim != null) { anim.SetBool("walk", true); anim.SetBool("attack", false); } }
private void OnMoveStarted(object sender, EventArgs e) { MoveStarted?.Invoke(sender, e); }