【问题标题】:Monogame/C# - Mouse position flickeringMonogame/C# - 鼠标位置闪烁
【发布时间】:2015-10-06 15:39:05
【问题描述】:

我在 MonoGame 中的鼠标位置有一些问题,我真的不知道我做错了什么。我希望游戏窗口位于光标所在的位置,所以我做了这么简单的一行:

protected override void Update(GameTime gameTime)
{
        Window.Position = new Point(Mouse.GetState().X, Mouse.GetState().Y);

        base.Update(gameTime);
}

但如果我这样做,游戏窗口会在两个位置之间闪烁。问题是什么 ?我是不是做错了什么?

谢谢!

【问题讨论】:

  • 出于好奇。你为什么要这么做?

标签: c# xna monogame


【解决方案1】:

好吧,当您考虑它时,它实际上是有道理的。我举个例子:

Cursor is 500,500 (in relation to Window)
Window is 300,300 (in relation to Screen)

The first time the code runs, it moves the window to 500,500. 
Meaning the cursor will now have a location of 300,300 (in relation to Window).

The second time the code runs, it will detect the mouse is now at 300,300, and thus move the Window back to 300,300.

因此它会永远运行。

要完成我认为你想要的,你需要考虑窗口的当前位置。

这意味着您必须“锁定”鼠标的位置(相对于窗口),并且每当这种情况发生变化时,将窗口移动鼠标位置移动的量。当然,再次将鼠标移回

【讨论】:

    猜你喜欢
    • 2011-09-05
    • 1970-01-01
    • 2014-10-21
    • 2011-01-31
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    相关资源
    最近更新 更多