Monogame/C#-鼠标位置闪烁

Monogame/C#-鼠标位置闪烁,c#,xna,monogame,C#,Xna,Monogame,我在MonoGame中的鼠标位置有点问题,我真的不知道我做错了什么。我希望游戏窗口位于光标的位置,所以我做了一条简单的线: protected override void Update(GameTime gameTime) { Window.Position = new Point(Mouse.GetState().X, Mouse.GetState().Y); base.Update(gameTime); } 但如果我这样做,游戏窗口会在两个位置之间闪烁。有

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

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

        base.Update(gameTime);
}
但如果我这样做,游戏窗口会在两个位置之间闪烁。有什么问题?我做错什么了吗


谢谢大家!

嗯,当你仔细想想的时候,它实际上是有道理的。让我举个例子:

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.
因此,它将永远运行

要实现我认为您想要的,您需要考虑窗口的当前位置


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

。你为什么要这么做?