This project is read-only.

Mouse cursor over video display

Apr 21, 2011 at 11:04 AM

Hi, I was trying to combine a user interface with AR. But when i overlay the user interface over the video from tutorial 8, the mouse cursor is hidden under the video display. Is there any solution other than creating my own 2d or 3d mouse cursor, and update it's position every frame?

Apr 21, 2011 at 11:07 AM


You can enable the cursor by  this.IsMouseVisible = true; in your constructor. Check this link it has more information on how to obtain mouse coordinates.


Apr 26, 2011 at 9:17 AM

that worked fine!

Jun 3, 2011 at 12:36 AM

How about if we want to change the cursor size and type?

Jun 3, 2011 at 3:08 PM

You would probably have to add an item to the UI2D, and bind it's position to the cursor's position.

Jun 3, 2011 at 3:08 PM

You would probably have to add an item to the UI2D, and bind it's position to the cursor's position.

Jun 3, 2011 at 4:04 PM

Can you just elaborate a little more fjhamming? an example?

Jun 4, 2011 at 12:20 AM

I think that I got it.

And here is how

Protected Override void LoadContent()



            // Cursor size
            int cursorSize = 64;
            // New SpriteBatch to draw 2d cursor
            cursorSprite = new SpriteBatch(GraphicsDevice);
            // Load the bitmap => If you want transparent => have to use .png or .gif
            System.Drawing.Bitmap cursorBitmap = new System.Drawing.Bitmap("Content\\handCursorpng.png");
            // Create new texture to hold cursor texture
            cursorTexture = new Texture2D(GraphicsDevice, cursorSize, cursorSize);
            // Extract pixels from loaded bitmap and copy into the texture
            Microsoft.Xna.Framework.Graphics.Color[] data = new Microsoft.Xna.Framework.Graphics.Color[cursorSize * cursorSize];
            for (int y = 0; y <  cursorSize; y++)
                for (int x = 0; x < cursorSize; x++)
                    System.Drawing.Color color = cursorBitmap.GetPixel(x,y);
                    data[x+y*cursorSize] = new Microsoft.Xna.Framework.Graphics.Color(color.R, color.G, color.B, color.A);


protected override void Draw(GameTime gameTime)

// Retrieve mouse position
            MouseState mState = Mouse.GetState();
            Vector2 mousePos = new Vector2(mState.X-11, mState.Y-2);
            // Draw cursor after base.Draw() in order to draw it after any DrawableGameComponent

            //cursorSprite.Draw(cursorTexture, mousePos,Color.White);
            cursorSprite.Draw(cursorTexture, mousePos, new Color(255, 255, 255, 255));


Assume that you already declared these variable

// A spriteBatch variable to test drawing the mouse
 private Microsoft.Xna.Framework.Graphics.SpriteBatch cursorSprite;
 // A texture2d variable to hold the cursor texture
private Microsoft.Xna.Framework.Graphics.Texture2D cursorTexture;


Hope that help.