【发布时间】:2016-12-23 10:26:28
【问题描述】:
我正在尝试使用 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);
}
我是 Phaser 的菜鸟,所以如果你在我的代码中看到一些奇怪的东西,请告诉我,我想学习 ;-)
谢谢你们的帮助。
【问题讨论】:
-
我在这里没有看到一行打字稿。
标签: javascript html phaser-framework