XNA|MonoGame's Mouse Input Examples

There is one c# course I am learning. There are ways to use your mouse to input and control the sprtes.

I collect these snippets of c# to use mouse.

  • Enable Mouse Visible

    IsMouseVisible = true;

  • Mouse Click to Active
    ButtonState previousState= ButtonState.Pressed;

    // Update
    if (mouse.LeftButton == ButtonState.Released && previousState==ButtonState.Pressed) {
    previousState = mouse.LeftButton;

  • Whether Sprite Contact The Mouse

    MouseState mouse=Mouse.GetState();

##In Summary

The key to flexibily to get mouse’s states and control by mouse is by combining ButtonState.