public void ScrollToPosition(int x, int y)
{
//Smoothly move to the new position
_moveToX = (int)(x - (_windowWidth / ZoomDistance) / 2);
_moveToY = (int)(y - (_windowHeight / ZoomDistance) / 2);
if (_moveToX > (Width - ((_windowWidth / ZoomDistance) * 0.9f)))
{
_moveToX = (int)(Width - ((_windowWidth / ZoomDistance) * 0.9f));
}
if (_moveToX < ((_windowWidth / ZoomDistance) / -10))
{
_moveToX = (int)((_windowWidth / ZoomDistance) / -10);
}
if (_moveToY > (Height - ((_windowHeight / ZoomDistance) * 0.9f)))
{
_moveToY = (int)(Height - ((_windowHeight / ZoomDistance) * 0.9f));
}
if (_moveToY < ((_windowHeight / ZoomDistance) / -10))
{
_moveToY = (int)((_windowHeight / ZoomDistance) / -10);
}
_moving = true;
//We want only a second to move to the position
float xDis = _moveToX - _cameraX;
float yDis = _moveToY - _cameraY;
float moveSpeed = (float)Math.Sqrt(xDis * xDis + yDis * yDis) * 2;
float angle = (float)(Math.Atan2(yDis, xDis));
_xVel = (float)(moveSpeed * Math.Cos(angle));
_yVel = (float)(moveSpeed * Math.Sin(angle));
_leftOfX = _moveToX < _cameraX;
_aboveOfY = _moveToY < _cameraY;
}