XNA 3.1 中的鼠标位置问题

发布于 2024-11-27 00:06:19 字数 911 浏览 0 评论 0原文

我正在使用 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);

        }

enter image description here
Regards
MGD

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难如初 2024-12-04 00:06:19

我能想到几个可能的原因。我看不出您发布的代码片段有任何直接错误,因此,如果这些问题都不能解决问题,请发布更多代码。

当您使用默认字体创建新的 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 using spriteBatch.Begin() with no arguments. Are you doing anything unusual like applying an Effects to your SpriteBatch drawing?

Are you drawing to a render target that is then redrawn to the screen?

愁杀 2024-12-04 00:06:19

如果我的游戏窗口实际上大于我运行游戏的计算机屏幕的分辨率,我会遇到鼠标位置问题,这看起来很奇怪。这是一个快速检查,但可能会有所帮助。 (还请记住,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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文