2016-10-02 20 views
0

我正在嘗試使用phaser.io製作一個小遊戲,並且我遇到了一些問題。HTML5遊戲Phaser.io以精靈方向製作武器火

我使用Phaser的武器物品來製造我的英雄發射子彈。

它工作良好,除非我打開左側,武器繼續發射權。

這裏是我的代碼(打字稿):

this.weapon = game.add.weapon(1500, 'shot'); 
this.weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; 
this.weapon.bulletSpeed = 750; 
this.weapon.fireRate = 2; 
this.weapon.bulletAngleVariance = 3; 
this.weapon.trackSprite(this, 0, 0, true); 

這裏的移動功能:

walk = (direction) => { 

    var speed; 
    if (this.isGrounded) { 
     speed = this.accel; 
    } else { 
     speed = this.airAccel; 
    } 
    if (direction == "right") { 
     if (this.body.velocity.x < this.maxSpeed) { 
      this.body.velocity.x += speed; 
      this.animations.play('walk', 9, true); 
      this.scale.x = 1; 
     } 

    } else if (direction == "left") { 
     if (this.body.velocity.x > -this.maxSpeed) { 
      this.body.velocity.x -= speed; 
      this.animations.play('walk', 9, true); 
      this.scale.x = -1; 
     } 
    } 
} 

和火災事件:

if (this.gamepad.justPressed(Phaser.Gamepad.XBOX360_X)) { 
    this.weapon.fire(null); 
} 

我與移相器一個小白,所以如果你在我的代碼中看到一些奇怪的東西,請告訴我,我想學習;-)

謝謝你們的幫助。

+0

我在這裏看不到一行打字稿。 – Azamantes

回答

1

只需根據您的移動方向更改weapon.fireAngle。

if (direction == "left") 
{ 
    this.weapon.fireAngle = Phaser.ANGLE_LEFT; 
} 
else if (direction == "right") 
{ 
    this.weapon.fireAngle = Phaser.ANGLE_RIGHT; 
}