private void dispatcherTimer_Tick(object sender, EventArgs e) { var top = Canvas.GetTop(this); var left = Canvas.GetLeft(this); switch (_direction) { case Direction.Down: Canvas.SetTop(SpriteSheet, 0); Canvas.SetTop(this, top + _movementSpeed); break; case Direction.Left: Canvas.SetTop(SpriteSheet, -48); Canvas.SetLeft(this, left - _movementSpeed); break; case Direction.Right: Canvas.SetTop(SpriteSheet, -96); Canvas.SetLeft(this, left + _movementSpeed); break; case Direction.Up: Canvas.SetTop(SpriteSheet, -144); Canvas.SetTop(this, top - _movementSpeed); break; } Canvas.SetLeft(SpriteSheet, DirectionControl.NextFrame()); }
public void Move(Key k) { currentKey = k; _direction = DirectionControl.GetDirection(k); DirectionControl.SetKeyDown(_direction); _timer.Start(); }
internal void Stop(Key k) { var key = DirectionControl.GetDirection(k); DirectionControl.StopKeyPress(key); if (DirectionControl.AllKeysLifted()) { _timer.Stop(); } }