我正试着用移相器做一个小游戏。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);
}
我是Phaser的新手,所以如果你在我的代码中看到一些奇怪的东西,请告诉我,我想学习;-)
谢谢你们的帮助。