简体   繁体   English

使用C ++(线程或计时器)进行游戏更新?

[英]Game Update in C++ (Threads or Timer)?

Recently I'm trying to create a Game by myself, and now I run into one question... I want to render my Game at 60 times per second, and that's good, but then I use Directinput8 to get my keyboard and mouse set up, And I Debug my Game... I found my keyboard also get update 60 times per sec. 最近,我试图自己创建一个游戏,现在我遇到一个问题...我想以每秒60次的速度渲染游戏,这很好,但是随后我使用Directinput8来设置键盘和鼠标,然后我调试游戏...我发现我的键盘每秒也更新60次。 for example I press 'UP' and my menu goes crazy! 例如,我按“ UP”,菜单就发疯了! I know I can use a few variable to fix this, but I also heard that Timer and Threads are helpful, may I ask some guy who once made a Game or know what I should do to give me some advise? 我知道我可以使用一些变量来解决此问题,但是我也听说Timer和Threads是有用的,请问曾经做过游戏的人,或者我应该怎么做才能给我一些建议? Anything will be helpful! 一切都会有帮助的! thanks! 谢谢! :) By the way I know there are some cool library(like Allegro?) that are done, maybe someone can tell me how did they conquer this "update and render" issue? :)顺便说一句,我知道已经完成了一些很酷的库(如Allegro?),也许有人可以告诉我他们是如何克服这个“更新和渲染”问题的?

Often there is a single rendering thread per game. 通常每个游戏只有一个渲染线程。 It periodically, say each second, updates the whole screen taking all the input you have at this moment. 它会每秒(例如每秒)定期更新整个屏幕,以获取您此时拥有的所有输入。 The input, such as keyboard and mouse, you collect outside of that thread and that thread gets it for each update. 您在该线程外部收集了输入(例如键盘和鼠标),并且该线程将在每次更新时获取该输入。

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

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