I have been rendering some custom "buttons" using SpriteBatch.Draw(). However today I realized that the coordinates at which I was supposedly drawing my buttons at was not consistent with the coordinates that my mouse claims they are being rendered at. This is an issue, as it is hard to detect if a button is being clicked if the graphical rendering is off. Another possibility is that the mouse coordinates are off. What is wrong?
If you need more information, please ask. Thank you!
Hardcoded button positions:
/// <summary>
/// The x position at which the left part of the buttons on the main menu begin.
/// </summary>
public static readonly int ButtonX = 20;
/// <summary>
/// How wide the buttons are.
/// </summary>
public static readonly int ButtonWidth = 200;
/// <summary>
/// How tall the buttons are.
/// </summary>
public static readonly int ButtonHeight = 50;
/// <summary>
/// The y position of the top of the new game button.
/// </summary>
public static readonly int NewGameButtonY = 100;
/// <summary>
/// The y position of the top of the new game button.
/// </summary>
public static readonly int QuitButtonY = 200;
Method of getting mouse position:
int x = Mouse.GetState().X;
int y = Mouse.GetState().Y;
How the buttons are rendered:
private static void DrawButton(MonoButton button, ref SpriteBatch spBatch)
{
if (button.Visible)
{
spBatch.Draw(button.Image, button.DrawingBounds, colorMask);
RenderingPipe.DrawString(MainMenuLayout.MainMenuFont, button.Text, button.DrawingBounds, Alignment.Center, colorMask, ref spBatch);
}
}
Visual display of how off SOMETHING is:
The top left corner of the new game button should be (20, 100).
EDIT: The native resolution of my laptop is 1920x1080, yet the game is definitely displaying in a lower resolution then that when in full screen mode.
EDIT #2: I realized later that while the mouse offset works, it is much easier to simply set your monogame window resolution to the native resolution of your moniter. This completely fixed the issue without a mouse offset.