1

私が作成した 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);
}
4

1 に答える 1

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が よりも大きい場合は、 がフレーム/更新ごとに 1 回減少することを確認する必要があり0ます。update()フレームごとにメソッドを呼び出すか、イベントをサブスクライブしENTER_FRAMEて、対応するイベント リスナーで更新を行うことができます。簡単なupdate()方法は次のようになります。

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

幸運を。

于 2012-04-22T14:00:03.850 に答える