Monogame/C# - 鼠标位置闪烁

Monogame/C# - Mouse position flickering

我在 MonoGame 中遇到鼠标位置问题,我无法真正弄清楚我做错了什么。我希望游戏 window 位于我的光标位置,所以我制作了这条简单的线:

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

        base.Update(gameTime);
}

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

谢谢!

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

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.

因此它永远运行。

要完成我认为您想要的,您需要考虑 Window 的当前位置。

这意味着你必须 "lock" 鼠标的位置(相对于 Window),并且每当它发生变化时,移动 Window鼠标位置移动。当然再把鼠标移回去