2011-01-07 89 views
1

這裏是我的代碼,我稱之爲主要拍攝每個循環的函數。這導致很高的火災率。我想增加一些延遲來獲得可能的2-3/s的RoF,但我知道如何做的唯一方法是延遲我的整個循環。在鏡頭之間添加延遲

void game::shooting(){ 

if (P->shoot()){ 
    for(int i=0;i<3;i++){ 
    VGCVector der = VGCVector (-5+5*i,5); 
    VGCVector hit = P->getPos(); 
    VGCVector calib = VGCVector (10,0); 
    hit= hit+calib; 
    SV.push_back(shot(hit,der,false)); 
    } 


} 
} 

回答

2
if (NextShootTime < CurrentTime) 
{ 
    Shoot(); 
    NextShootTime = CurrentTime + ShootDelay; 
} 

初始化NextShootTime爲0,你設置。

如果幀率非常低,您可能還希望在一幀中處理排隊多個項目符號。

+0

這是一個很好的化身! – grapefrukt 2011-01-07 11:15:03

0

你需要通過幀的時間,並檢查這與預期的火災率。