2016-04-17 16 views
0

こんにちは私は、プレーヤーが画面に触れるたびに弾丸を生成する機能を持っています。弾丸の発射速度または生成速度位相器

弾丸の量を制限する方法はありますか?基本的に私は非常に迅速に弾丸の多くが生成されますが、私は少なくとも毎秒2または3の代わりにiに制限したいと思います。あなた以下

私の発射機能と私の弾丸作成機能を見つけることができます。

createBullets: function(){ 
    //Bullets 
    this.bullets = this.add.group(); 
    this.bullets.enableBody = true; 
    this.bullets.physicsBodyType = Phaser.Physics.P2JS; 
    this.bullets.createMultiple(500, 'bullet', 0, false); 
    this.bullets.setAll('anchor.x', 0.5); 
    this.bullets.setAll('anchor.y', 0.5); 
    this.bullets.setAll('outOfBoundsKill', true); 
    this.bullets.setAll('checkWorldBounds', true);  

}, 

fireBullet: function(){ 
    this.bullet = this.bullets.getFirstExists(false); 
    if (this.bullet) { 
     this.bullet.reset(this.tanque.x, this.tanque.y - 20); 
     this.bullet.body.velocity.y = -500; 
    } 
}, 

と私の更新機能:

if(this.input.activePointer.isDown){ 
    if (!this.mouseTouchDown) { 
     this.touchDown(); 
    } 
}else { 
    if (this.mouseTouchDown) { 
     this.touchUp(); 
    } 
} 

私は本当に感謝すべてのヘルプを。

  1. nextShotTime:ショットが
  2. shotDelayを焼成することができる次の時間:ショット間の遅延(Phaser.Timer.SECOND * 2のように設定することができます)

Iドン

答えて

0

は私が前にゲームで同様の問題がありました。私が使用したソリューションは、上記のものと同じです。私はこれでこれを見つけた Phaser tutorial。チュートリアルで使用

火災機能は次のとおりです。

fire: function() { 
if (this.nextShotAt > this.time.now) { 
    return; 
} 

this.nextShotAt = this.time.now + this.shotDelay; 

あなたはあなたの目的に合わせて変更することができます。これはいくつかの方法であなたを助け

fire: function() { 
    //Make sure the player can't shoot when dead and that they are able to shoot another bullet 
     if(!this.player.alive || this.time.now < this.nextFireTime) { 
      return; 
     } 

     this.nextFireTime = this.time.now + this.fireRate; 

     var bullet; 
      //If weaponlvl = 0, shoot a normal bullet 
      if(this.weaponlvl === 0) { 
       if(this.bullet1.countDead() === 0) { 
        return; 
       } 
       //Properties for the basic weapon 
       this.fireRate = 500; 
       bullet = this.bullet1.getFirstExists(false); 
       bullet.reset(this.player.x, this.player.y-22); 
       bullet.body.velocity.y = -300; 
      } 

希望:

これは私が私が作ったゲームで使用される防火機能の一部です。

1

1つのオプションは、2つの値を格納することです上の例のコードでfireBullet()をどこに呼んでいるのかは分かりませんが、電話をかける前に、または関数内でnextShotTimeが過去であるかどうかを確認することができます。そうであれば、別の弾丸を発射して、shotDelayを加えた現在時刻でnextShotTimeを更新します。例えば

if (this.nextShotTime < this.time.now) { 
    this.nextShotTime = this.time.now + this.shotDelay; 
    // add your code that will fire a bullet. 
}