当前位置:网站首页>The latest tank battle 2022 - full development notes-3
The latest tank battle 2022 - full development notes-3
2022-07-29 05:20:00 【CPP programming】
8、 ... and 、 Create a tour loop
8.1 Create the main loop of the game 、
int main(void) {
init();
createMyTank();
createEnemyTank();
while (1) {
updataMap();
updataAllTanks();
}
system("pause");
return 0;
}8.2 Use time counting to optimize the loop
The cycle structure of the previous step , Keep refreshing , It seriously consumes the performance of the system , It must be improved . The easiest way , Use time counting to process . Be careful , Use it directly Sleep It will affect the timely response of the game .
bool updata; // Whether to update , And in init Function is initialized to true
int main(void) {
init();
createMyTank();
createEnemyTank();
int time = 0;
while (1) {
time += getDelay();
if (time >= 20) {
updata = true;
time = 0;
}
if (updata) {
updata = false;
BeginBatchDraw();
updataMap();
updataAllTanks();
EndBatchDraw();
}
}
system("pause");
return 0;
} Today's sharing is here , Everyone should study hard C Language /C++ yo ~
Welcome to change careers and learn programming partners , Using more information to learn and grow faster than thinking about it yourself !
For preparing to learn C/C++ Programming partners , If you want to better improve your core programming skills ( Internal skill ) From now on !
Organize and share ( Years of learning source code 、 Project practice video 、 Project notes , Introduction to Basics ) Add the group below to get ~
C Language C++ Programming learning communication circle ,QQ Group :763855696 【 Click to enter 】
C Language from entry to mastery (C Introduction to language C Language course C Language zero basis C Language foundation C Language learning C
边栏推荐
猜你喜欢
随机推荐
TCP三次握手四次挥手
About the configuration and use of thymeleaf
How to add a map to the legendary server
VirtualBox has expanded the capacity of virtual hard disk (without modifying the original data)
ARFoundation从零开始9-AR锚点(AR Anchor)
Pivot table of odoo development tutorial
Apache POI实现Excel导入读取数据和写入数据并导出
JS daily question (12)
向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!
7.3-function-templates
力扣------对奇偶下标分别排序
Mysql语句中的函数
时间序列分析的表示学习时代来了?
Learn the first program of database
Unity Metaverse(三)、Protobuf & Socket 实现多人在线
Mysql的自连接和联合查询
Open source Huizhi creates the future | the openeuler sub forum of 2022 open atom global open source summit was successfully held
The song of the virtual idol was originally generated in this way!
Unity metaverse (III), protobuf & socket realize multi person online
传奇如何一台服务器配置多个版本微端更新









