XNA 3.1 中的鼠标位置问题
我正在使用 XNA 3.1 进行游戏开发,我对鼠标位置没有什么问题,我还提供了问题的屏幕截图,现在在下面的代码中我尝试在鼠标处精确显示文本“Start”位置,但文本的位置距光标大约 200 - 250 像素,而不是与光标在游戏窗口上的同一点。
void MenuMainMenuDraw()
{
// Main Menu After Draw
// Menu Option After Draw
MouseState ms = Mouse.GetState();
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);
}
问候 MGD
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();
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
MGD
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到几个可能的原因。我看不出您发布的代码片段有任何直接错误,因此,如果这些问题都不能解决问题,请发布更多代码。
当您使用默认字体创建新的
SpriteFont
时是否会出现同样的问题?这可能是您当前使用的字体的间距问题。在您的 spriteBatch.Begin(...) 代码中您是否提供了transformMatrix?如果是这样,请尝试仅使用不带参数的
spriteBatch.Begin()
。您是否正在做任何不寻常的事情,例如将Effect
应用于 SpriteBatch 绘图?您是否正在绘制一个渲染目标,然后将其重新绘制到屏幕上?
There 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 usingspriteBatch.Begin()
with no arguments. Are you doing anything unusual like applying anEffect
s to your SpriteBatch drawing?Are you drawing to a render target that is then redrawn to the screen?
如果我的游戏窗口实际上大于我运行游戏的计算机屏幕的分辨率,我会遇到鼠标位置问题,这看起来很奇怪。这是一个快速检查,但可能会有所帮助。 (还请记住,XNA 从中心点绘制图像,但我相信默认情况下从文本的左上角绘制测试)。希望有帮助
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