I have a class that holds my enemy player object and I want it to collide with my player object however when I spawn multiple enemies it only collides with the original piece.
My enemy class:
class Enemy extends Phaser.Physics.Arcade.Sprite {
turret
constructor(scene, x, y, texture) {
super(scene, x, y, texture = 'player2', 'tank1')
scene.add.existing(this);
scene.physics.add.existing(this);
scene.events.on('update', this.update, this);
scene.physics.world.enableBody(this, 0);
//var x = Phaser.Math.RND.between(0, 800);
//var y = Phaser.Math.RND.between(0, 600);
this.name = this.enemytank;
this.setOrigin(0.5, 0.5);
this.setCollideWorldBounds(true);
this.body.setVelocity(100, 0);
this.body.bounce.setTo(1, 1);
//this.physics.velocityFromRotation(this.rotation, 100, this.body.velocity);
this.turret = new turret(scene);
this.shadow = new shadow(scene);
}
update() {
this.turret.follow(this);
this.shadow.follow(this);
}
}
create () {
for (var i = 0; i < blength; i++)
{
b = this.physics.add.existing (new Enemy(this, Phaser.Math.Between(-200, this.game.config.width), Phaser.Math.Between(-200, this.game.config.height)));
}
}
update() {
this.physics.add.collider(player, b);
}
any ideas would be grateful