I am trying to collide my Enemy class with my player sprite however it only collides with one of the enemy tanks. I have a for loop that calls multiple enemies.
here is my 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)
//var x = Phaser.Math.RND.between(0, 800);
//var y = Phaser.Math.RND.between(0, 600);
this.setOrigin(0.5, 0.5);
this.setCollideWorldBounds(true);
this.setVelocity(100, 0);
this.body.bounce.setTo(1, 1);
this.turret = new turret(scene);
this.shadow = new shadow(scene);
//this.physics.velocityFromRotation(this.rotation, currentSpeed, this.body.velocity);
}
update() {
this.turret.follow(this);
this.shadow.follow(this);
}
}
//add player object
player = this.physics.add.sprite(config.width/2, config.height/2, ‘player’, ‘tank1’);
player.setOrigin(0.5, 0.5);
player.setCollideWorldBounds(true);
player.body.drag.set(0.2);
player.body.maxVelocity.setTo(400, 400);
player.body.bounce.setTo(1, 1);
playershadow = this.physics.add.image(0, 0, ‘player’, ‘shadow’).setAlpha(0.6);
playershadow.setOrigin(0.5, 0.5);
//spawn multiple enemies
for (var i = 0; i < 20; i++)
{
enemy = new Enemy(this, Phaser.Math.Between(-200, this.game.config.width), Phaser.Math.Between(-200, this.game.config.height));
}