From adfdf963d8ce033e9eacef6fa0df54bd75d7f02d Mon Sep 17 00:00:00 2001 From: Simon Holmberg Date: Fri, 28 Sep 2012 14:41:57 +0200 Subject: [PATCH] Selection rectangle now behaves properly with the camera --- DepthsBelow/DepthsBelow/MouseInput.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index eda4116..3faf64b 100644 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -39,6 +39,7 @@ namespace DepthsBelow public void Update(GameTime gameTime) { MouseState ms = Mouse.GetState(); + Vector2 mouseWorldPos = core.camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); KeyboardState ks = Keyboard.GetState(); // Selection rectangle @@ -46,12 +47,12 @@ namespace DepthsBelow { 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 { - selectionRectangle.Width = ms.X - selectionRectangle.X + (int)core.camera.Position.X; - selectionRectangle.Height = ms.Y - selectionRectangle.Y + (int)core.camera.Position.Y; + selectionRectangle.Width = (int)mouseWorldPos.X - selectionRectangle.X; + selectionRectangle.Height = (int)mouseWorldPos.Y - selectionRectangle.Y; } } if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty) @@ -68,9 +69,8 @@ namespace DepthsBelow } // Grid highlighting - Vector2 clickWorldPos = core.camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); - Point clickGridPos = Grid.WorldToGrid(clickWorldPos); - Vector2 rectWorldPos = Grid.GridToWorld(clickGridPos); + Point mouseGridPos = Grid.WorldToGrid(mouseWorldPos); + Vector2 rectWorldPos = Grid.GridToWorld(mouseGridPos); gridRectangle = new Rectangle((int)rectWorldPos.X, (int)rectWorldPos.Y, Grid.TileSize, Grid.TileSize); lastMouseState = ms;