Aethelgard/js/objects/Bullet.js

14 lines
496 B
JavaScript

export default class Bullet extends Phaser.Physics.Arcade.Sprite {
constructor(scene, x, y, texture, target) {
super(scene, x, y, texture);
scene.physics.world.enable(this);
scene.add.existing(this);
this.setDepth(2);
this.speed = 600;
const angle = Phaser.Math.Angle.Between(x, y, target.x, target.y);
scene.physics.velocityFromRotation(angle, this.speed, this.body.velocity);
this.body.setAllowGravity(false);
this.body.setCollideWorldBounds(false);
}
}