Monday, June 18, 2012

Track MouseWheel in XNA

Photo courtesy : ehow.com 
Sometimes in your XNA Application you might need to track the mousewheel event to do some task. Luckily XNA has inbuilt function for this. MouseState class has a property called ScrollWheelValue which returns the current MouseWheel value. 


As the documentation specifies,
ScrollWheelValue : Gets the cumulative mouse scroll wheel value since the game was started.


Unlike Winforms, in XNA ScrollWheelValue reports the total scroll wheel value. To get the wheel movement you must track and compare with the previous ScrollWheelValue. 


MouseState mouseState = Mouse.GetState();

float ScrollWheelChange =mouseState.ScrollWheelValue;

No comments:

Post a Comment