c++ openGL 连续按下按钮
我正在 C++ 上使用 openGL 构建一些简单的游戏。 我在按下某个键时有一些动作。 我希望它是连续的,但我的问题是,在按下按键(键盘上)后的第一秒,系统将其称为单击,我的游戏对象进行一次移动,一秒钟后它会连续移动。 有什么想法可以解决这个问题吗? 谢谢。
I'm building some simple game with openGL on C++.
I have some movement while pressing some key.
I want it to be continuous but my problem is that on the first second after pressing the key (on the keyboard) the system refers to it as a single click, my game object makes one move and after a second it stats to move continuously.
Some ideas to solve this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该有一个全局布尔值(或者更好的是,一个包含不同键的所有布尔值的结构),在初始按键时设置为 true ,在按键释放时设置为 false 。然后你在执行操作时检查这个布尔值。
You should have a global boolean (or better yet, a struct with all your bools for the different keys) that is set to true on the initial keypress and set to false on key release. Then you check this bool when you do your action.
如果是特殊键,请使用
glutKeyboardUpFunc
或glutSpecialUpFunc
。两者都会告诉您用户何时释放按键。Use
glutKeyboardUpFunc
orglutSpecialUpFunc
if it's a special key. Both tell you when the user has released a key.