Adding a Cursor in XNA
If you want to add mouse cursor functionality to your XNA project you can simply add the following in your Initialize() method:
this.IsMouseVisible = true;
Then of course, where’s the fun in that, right? Real cursor functionality consists on you adding your own 2D Texture to represent your mouse, this is actually pretty easy to do, first of all, you will need the texture, typically, a cursor texture has its hotspot (The tip of the arrow from where you click) on the upper-left corner of the image. Your cursor could be any size, try not to make it too big or too small.
Here’s an example:
![]()
Let’s add a few global variables:
Texture2D cursorTexture; Vector2 cursorPosition;
Now load the texture in your LoadContent() method:
cursorTexture = Content.Load("cursor"); //Use your asset name.
On our Update() method, we’ll pass over the mouse’s position to our cursorPosition variable:
cursorPosition.X = Mouse.GetState().X; cursorPosition.Y = Mouse.GetState().Y;
Lastly, we need to draw our cursorTexture with the continuously changing cursorPosition, we do this of course in our Draw() method:
spriteBatch.Begin(); spriteBatch.Draw(cursorTexture, cursorPosition, Color.White); spriteBatch.End();
Simple as that, try it out!
Happy coding!



Cool! Thanks a lot!