I'm trying to make a little game with phaser.io and I have a little problem.
I use the weapon object of Phaser to make my hero fire bullets.
It's working good except when I turn on the left, the weapon keeps firing right.
Here's my code (in typescript) :
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);
Here's the move function :
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;
}
}
}
and the fire event:
if (this.gamepad.justPressed(Phaser.Gamepad.XBOX360_X)) {
this.weapon.fire(null);
}
I'm a noob with Phaser, so if you see something strange in my code, please tell me, I want to learn ;-)
Thank you guys for your help.