researchzuloo.blogg.se

Get mouse coordinates in game
Get mouse coordinates in game













get mouse coordinates in game

It gives a kinda funky result if you have multiple monitors but if it's the same kind of funky that you're seeing for mouse position, you should be able to just subtract it and get the right answer. This might be a bug in MonoGame, or it might be something specific about how your machine is configured, or some cross between those two things.Īs a workaround, (and the answer to your original question) Window.Position gets you the position of the game window in screen coords (your Game1 class should have access to Window as a property). For some reason, on your machine, it's not doing that. _spriteBatch.DrawString(font, "Mouse Position: " + MousePos.X + " " + MousePos.Y, new Vector2(50, 50), Color.Red) įor posterity (and future people having the same bug as OP) Mouse Position is supposed to be in window coordinates. GraphicsDevice.Clear(Color.CornflowerBlue) Protected override void Draw(GameTime gameTime) Vector2 MousePos = new Vector2(mouseState.X, mouseState.Y) Probably excessive, but I wanted to be sure MouseState mouseState = .Mouse.GetState() Protected override void Update(GameTime gameTime) If it is screen-centric, then is there a way to get the window's position relative to the screen, since then it would just be a simple subtraction to get the window coordinates?

#Get mouse coordinates in game update#

The MouseState object is being initialised in the update method, if that has any connection to why its behaving like it is. Is mouse-state not window-centric, or have I missed something. 0,0 is the top right corner of the window), but when I load up the game window, it is screen relative. So I've been learning monogame recently, and have come across a hurdle when it comes to getting the mouse's position.įrom what I've read, the coordinates given from Input.MouseState are window-centric (i.e.















Get mouse coordinates in game