简体   繁体   中英

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. for example I press 'UP' and my menu goes crazy! 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? 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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