Selection rectangle now behaves properly with the camera
This commit is contained in:
@@ -39,6 +39,7 @@ namespace DepthsBelow
|
|||||||
public void Update(GameTime gameTime)
|
public void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
MouseState ms = Mouse.GetState();
|
MouseState ms = Mouse.GetState();
|
||||||
|
Vector2 mouseWorldPos = core.camera.ScreenToWorld(new Vector2(ms.X, ms.Y));
|
||||||
KeyboardState ks = Keyboard.GetState();
|
KeyboardState ks = Keyboard.GetState();
|
||||||
|
|
||||||
// Selection rectangle
|
// Selection rectangle
|
||||||
@@ -46,12 +47,12 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
if (selectionRectangle == Rectangle.Empty)
|
if (selectionRectangle == Rectangle.Empty)
|
||||||
{
|
{
|
||||||
selectionRectangle = new Rectangle(ms.X + (int)core.camera.Position.X, ms.Y + (int)core.camera.Position.Y, 0, 0);
|
selectionRectangle = new Rectangle((int)mouseWorldPos.X, (int)mouseWorldPos.Y, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
selectionRectangle.Width = ms.X - selectionRectangle.X + (int)core.camera.Position.X;
|
selectionRectangle.Width = (int)mouseWorldPos.X - selectionRectangle.X;
|
||||||
selectionRectangle.Height = ms.Y - selectionRectangle.Y + (int)core.camera.Position.Y;
|
selectionRectangle.Height = (int)mouseWorldPos.Y - selectionRectangle.Y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty)
|
if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty)
|
||||||
@@ -68,9 +69,8 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Grid highlighting
|
// Grid highlighting
|
||||||
Vector2 clickWorldPos = core.camera.ScreenToWorld(new Vector2(ms.X, ms.Y));
|
Point mouseGridPos = Grid.WorldToGrid(mouseWorldPos);
|
||||||
Point clickGridPos = Grid.WorldToGrid(clickWorldPos);
|
Vector2 rectWorldPos = Grid.GridToWorld(mouseGridPos);
|
||||||
Vector2 rectWorldPos = Grid.GridToWorld(clickGridPos);
|
|
||||||
gridRectangle = new Rectangle((int)rectWorldPos.X, (int)rectWorldPos.Y, Grid.TileSize, Grid.TileSize);
|
gridRectangle = new Rectangle((int)rectWorldPos.X, (int)rectWorldPos.Y, Grid.TileSize, Grid.TileSize);
|
||||||
|
|
||||||
lastMouseState = ms;
|
lastMouseState = ms;
|
||||||
|
|||||||
Reference in New Issue
Block a user