繁体   English   中英

Monogame / C#-鼠标位置闪烁

[英]Monogame/C# - Mouse position flickering

我在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.

因此,它永远运行。

要实现我认为想要的功能,您需要考虑Window的当前位置。

这意味着您必须“锁定”鼠标的位置(相对于Window),并且每当更改此位置时,就将Window移动到鼠标位置移动的量。 当然还要再次将鼠标移回

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM