简体   繁体   English

SFML输入GetMouseX和GetMouseY无法赶上鼠标移动

[英]SFML Input GetMouseX and GetMouseY not catching on to mouse movement

I'm programming a GUI in my app and I noticed that button presses weren't being registered very quickly. 我在我的应用程序中编写了一个GUI,我注意到按钮的注册不是很快。 I did some lazy debugging (send coordinates of mouse to output) and I noticed that Input's GetMouseX and GetMouseY weren't responding nearly fast enough to when the mouse moved somewhere. 我进行了一些懒惰的调试(将鼠标的坐标发送到输出),并且我注意到Input的GetMouseX和GetMouseY的响应速度几乎没有鼠标移动到某个地方时足够快。

This small tidbit should be able to reproduce it (in a HandleEvents function that is called in a typical game loop, obviously replace App::whatever with whatever you have in your workspace). 这个小花絮应该能够重现(在典型的游戏循环中调用的HandleEvents函数中,显然用工作空间中的任何内容替换App :: whatever)。

int x = App::GetApp()->GetInput().GetMouseX();
int y = App::GetApp()->GetInput().GetMouseY();
std::cout << x << " " << y << "\n";

Just move your mouse around on the screen and watch the output. 只需在屏幕上移动鼠标并观看输出即可。 I'm not sure if this is correct behavior and I'm using it for the wrong purpose, or what, but I need some way to retrieve the mouse's exact location at any given time. 我不确定这是否是正确的行为,是否将其用于错误的目的或用于什么目的,但是我需要某种方式在任何给定时间检索鼠标的确切位置。 Any help is appreciated, thanks. 任何帮助表示赞赏,谢谢。

PS If I move the mouse slowly the problem doesn't occur. PS:如果我缓慢移动鼠标,则不会出现此问题。

Edit: 编辑:

I was wrong. 我错了。 The problem only occurs in context with the rest of the stuff going on. 该问题仅在上下文中发生,而其余部分仍在继续。 When I blocked out most of the game loop and only included retrieving cursor position, it worked fine. 当我阻止了大部分游戏循环并且仅包括获取光标位置时,它工作正常。 Still not sure what is wrong though. 仍然不确定什么地方出了问题。

问题是我只每帧轮询一个事件,而不轮询所有事件。

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

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