Mouse
Introduction
The Mouse class provides functionality for getting input data from the physical mouse. This class is automatically instantiated by and accessible through the InputManager.
Detecting Mouse Activity
There are many ways to get data from the mouse. The following section of code is a series of if-statements which could be used to detect input from the mouse.
Mouse Scroll Wheel
The mouse scroll wheel is exposed through the InputManager.Mouse.ScrollWheel property. The ScrollWheel property returns the number of "clicks" that the scroll wheel has moved since last frame. The following code controls the Z position of the camera based on the ScrollWheel property.
Mouse Pixel Coordinates
The Mouse class provides information about the cursor's pixel coordinates.
The mouse coordinates are top left justified, so (0,0) represents the top left corner of the screen. Keep in mind that the pixel coordinates are relative to the top-left of the screen, but not bound by your game screen. That means that if the cursor is to the left (outside of) your game screen, then the X value will be negative. Also, the mouse will continue to return values when the cursor is to the right or below the game screen, resulting in values which are potentially larger than the width or height of the screen.
Mouse World Coordinates
The Mouse reports the world coordinates of the cursor through the functions WorldXAt and WorldYAt.
Detecting Mouse in Window
Certain activities should only occur if the mouse is in the window. To test for this, use the following code: Add the following using statement:
The following code performs the check:
Last updated