I am using XNA 3.1 for the a game development, I am having little issue with the mouse position, I am also providing the screen shots of the issue, for now in the code below I am trying to display text "Start" exactly at mouse Position but the location of the the text is around 200 - 250 pixels away from the cursor instead to be at the same point where the cursor is on game window.
void MenuMainMenuDraw()
{
// Main Menu After Draw
// Menu Option After Draw
MouseState ms = Mouse.GetState();
开发者_StackOverflow中文版 spriteBatch.DrawString(fontMenu, "Start"
, new Vector2(ms.X, ms.Y)
, Color.Red);
spriteBatch.DrawString(fontMenu, "Options"
, new Vector2((float)MENU_GLOBAL.MENU_POSITION_X, (float)MENU_GLOBAL.OPTION_POSITION_Y)
, Color.Red);
spriteBatch.DrawString(fontMenu, "Leader's Board"
, new Vector2((float)MENU_GLOBAL.MENU_POSITION_X, (float)MENU_GLOBAL.HIGHSCORE_POSITION_Y)
, Color.Red);
}
Regards
MGDThere are a few possible causes that I can think of. I can't see anything directly wrong with the code snippet that you posted, so if none of these things resolve it, post more of your code.
Does the same problem occur when you create a new SpriteFont
using the default font face? It may be a problem with the spacing in the font you're currently using.
In your spriteBatch.Begin(...)
code are you supplying a transformMatrix? If so, try just using spriteBatch.Begin()
with no arguments. Are you doing anything unusual like applying an Effect
s to your SpriteBatch drawing?
Are you drawing to a render target that is then redrawn to the screen?
I've had mouse position issues that seemed strange if my game window was actually larger than the resolution of the computer screen that I was running the game on. Its a quick check but it just might help. (Also remember that XNA draws images from the center point, but I believe by default draws test from the text's upper left corner). Hope that helps
精彩评论