XNA Game Component – Custom Mouse Pointer

Mykre has posted a nice tutorial on a custom mouse pointer in XNA.

From the article:

For a while I have had some basic code to handle mouse functions in XNA Applications,

* Custom Mouse Pointer
* XNA Mouse Interface
* Virtual Realm XNA Input Manager

But as some of these are old and each have some different functions I thought this morning that I would put the simple mouse functions into a Drawable XNA Game Component. The component that I have put together will draw a custom mouse pointer on the screen and restrict the pointer to the current game window, when you leave the window the mouse will return to the normal mouse pointer you use in windows. At the same time the mouse will change color when the mouse buttons are pressed. There are a lot more functions that could be added to this, for example handling the wheel or adding events to the mouse states. One of the functions that I will be adding soon is a shadowed effect to the mouse pointer.

To use this game component add the following code to the top of the game class just under the initialization for the game manager and content manager so that it looks like this…