2012-04-22 125 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