How to tell if the mouse is moving in c#

Go To StackoverFlow.com

-2

Possible Duplicate:
XNA Mouse Movement

Basically, I am creating a game using XNA, and I need a way of telling if the mouse is moving. Any help is greatly appreciated. thanks in advance!

2012-04-03 21:33
by hazard1994


0

You can capture and store the mouse position in the Update() method of your game loop. Then, you can compare the stored mouse position with the current mouse position. If the values differ, the mouse has moved.

2012-04-03 21:40
by njebert
Thanks for the help - hazard1994 2012-04-04 14:54


0

Use MouseState and compare the previous MouseState to the current MouseState

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.mousestate_members.aspx? http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Mouse_camera.php

MouseState currentMouseState = Mouse.GetState();
if (currentMouseState != originalMouseState)
{
    //The mouse did something
}

You could compare MouseState.X and MouseState.Y if you only care about movement

2012-04-03 21:39
by Murtnowski
I figured it out for myself, but thanks for the help anyway: - hazard1994 2012-04-04 14:54
Ads