关于对游戏帧率的学习

来源:互联网 发布:数据分析与r语言05 编辑:程序博客网 时间:2024/05/16 19:50

    先看传统的游戏消息主循环:

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);

 }

把更新游戏画面和逻辑都放进那里面,就可以到达目的了~~ 

原创粉丝点击