I have a menu (Myra-Menu) with some buttons on it. The problem that I have is that I have an offset. So, when i move my cursor close to a button (but still not on that button) the hoover effect is already fires.
This is happening since I use the Independent Resolution Rendering, see http://www.david-amador.com/2010/03/xna-2d-independent-resolution-rendering/.
I do not understand how I can adjust my mouse coordinates so that the hoover (or click) effect is happening when the visual cursor is actually on it.
My idea was that everytime Update (GameTime gameTime) is called, I add an offset to my current mouse coordinates. I hope that my offset calculations are correct. Something like:
Vector2 mousePosition = Mouse.GetState().Position.ToVector2(); Vector2 viewport = new Vector2 (graphics.GraphicsDevice.Viewport.X, graphics.GraphicsDevice.Viewport.Y); Vector2 deltaPosition = mousePosition - viewport; Matrix transformationMatrix = Matrix.CreateScale((float)graphics.GraphicsDevice.Viewport.Width / 1280, (float)graphics.GraphicsDevice.Viewport.Height / 860, 1f); Matrix invertTransformationMatrix = Matrix.Invert(transformationMatrix); Vector2 mousePositionAdjusted = Vector2.Transform(deltaPosition, invertTransformationMatrix); Mouse.SetPosition((int)mousePositionAdjusted.X, (int)mousePositionAdjusted.Y);
When I do this, my mouse cursor automatically (everytime Update has been called) moves a bit closer to the coordinate 0,0 (which acutally makes sense to me). But still my problem remains: How can I offset my mouse cursor (all the time)?