2012-04-22 69 views
1

我想在我已經制作的Actionscript 3遊戲中限制我的子彈的射擊速度。任何幫助將非常感激。以下是我的代碼。在Actionscript 3遊戲中設置子彈的射擊速度

//shooting bullet 
function shoot(Evt:MouseEvent) 
{ 
    var sound2 = new bullet_shoot(); 
    sound2.play(); 
    if (bulletCounter < 5) 
    { 
     bulletCounter++; 
    } 
    else 
    { 
     bulletCounter = 0; 
    } 
    shootmc(bulletArray[bulletCounter]); 
} 

function shootmc(mc:MovieClip) 
{ 
    mc.visible = true; 
    mc.x = spaceman_mc.x; 
    mc.y = spaceman_mc.y; 
    mc.gotoAndPlay(2); 
} 

回答

1

function shoot(),設置如果大於0其防止拍攝的延遲/倒計時變量。例如:

function shoot(Evt:MouseEvent) { 
    if (shootDelay == 0) { 

     // set shoot delay 
     shootDelay = 10; 

     // shoot logic 
     var sound2 = new bullet_shoot(); 
     if (bulletCounter < 5) bulletCounter++; 
     else bulletCounter = 0; 
     shootmc(bulletArray[bulletCounter]); 
    } 
} 

現在,你仍然必須確保shootDelay在每週幀/更新,如果它比0較大的下降,否則你將永遠無法再次觸發。您可以每幀調用update()方法,或者訂閱ENTER_FRAME事件,並在相應的事件偵聽器中進行更新。簡單的update()方法看起來像這樣:

public function update():void { 
    if (shootDelay > 0) shootDelay --; 
} 

祝你好運。

+0

更多的有用將比ENTER_FRAME setInterval,因爲事件取決於幀率 – turbosqel 2012-04-23 08:45:13