先看传统的游戏消息主循环:
while(1)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message==WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
//there is no message and now to due the game logic
if(bActive)
{
thisTick=GetTickCount();
if(thisTick-lastTick>1000)
{
lastTick=thisTick;
FPS=count;
count=0;
}
else
count++;
MakeScene();
Flip(lpDDSPrimary,lpDDSBack);
}
}
}
如果我们要把游戏限制在一定的帧数怎么做呢?很简单,假如我们要把帧数限制在30,那么每帧就需要----
1/30秒~~即为1000/30毫秒~~这样的话就可以这样做
if(thisTick-lastTick>1000/30)
{
lastTick=thisTick;
MakeScene();
Flip(lpDDSPrimary,lpDDSBack);
}
把更新游戏画面和逻辑都放进那里面,就可以到达目的了~~
1774

被折叠的 条评论
为什么被折叠?



