Hello good morning,
So far I am working on a shooter game where the player defends himself by shooting the enemies but right now I just added a ton of enemy images to the game which is not efficient so I want to add an enemy group instead, does anyone know how to do this?
this is the code for the enemies so far.
this.enemy = this.physics.add.sprite(600, 800, 'enemy').setScale(.9);
this.enemy.setCollideWorldBounds(true);
this.enemy1 = this.physics.add.sprite(700, 400, 'enemy1').setScale(.9);
this.enemy1.setCollideWorldBounds(true);
this.enemy2 = this.physics.add.sprite(800, 200, 'enemy2').setScale(.9);
this.enemy2.setCollideWorldBounds(true);
this.enemy3 = this.physics.add.sprite(555, 300, 'enemy3').setScale(.9);
this.enemy3.setCollideWorldBounds(true);
this.enemy4 = this.physics.add.sprite(800, 100, 'enemy4').setScale(.9);
this.enemy4.setCollideWorldBounds(true);
this.enemy5 = this.physics.add.sprite(599, 400, 'enemy5').setScale(.9);
this.enemy5.setCollideWorldBounds(true);
this.enemy6 = this.physics.add.sprite(698, 676, 'enemy6').setScale(.9);
this.enemy6.setCollideWorldBounds(true);
this.enemy7 = this.physics.add.sprite(778, 845, 'enemy7').setScale(.9);
this.enemy7.setCollideWorldBounds(true);
this.enemy8 = this.physics.add.sprite(456, 789, 'enemy8').setScale(.9);
this.enemy8.setCollideWorldBounds(true);
this.enemy9 = this.physics.add.sprite(1000, 600, 'enemy9').setScale(.9);
this.enemy9.setCollideWorldBounds(true);
this.enemy10 = this.physics.add.sprite(600, 600, 'enemy10').setScale(.9);
this.enemy10.setCollideWorldBounds(true);
this.physics.add.collider(this.player, this.enemy, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy1, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy2, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy3, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy4, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy5, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy6, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy7, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy8, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy9, this.playerDie, null, this);
this.physics.add.collider(this.player, this.enemy10, this.playerDie, null, this);
enemyFollows() {
this.physics.moveToObject(this.enemy, this.player, 50);
this.physics.moveToObject(this.enemy1, this.player, 50);
this.physics.moveToObject(this.enemy2, this.player, 50);
this.physics.moveToObject(this.enemy3, this.player, 50);
this.physics.moveToObject(this.enemy4, this.player, 50);
this.physics.moveToObject(this.enemy5, this.player, 50);
this.physics.moveToObject(this.enemy6, this.player, 50);
this.physics.moveToObject(this.enemy7, this.player, 50);
this.physics.moveToObject(this.enemy8, this.player, 50);
this.physics.moveToObject(this.enemy9, this.player, 50);
this.physics.moveToObject(this.enemy10, this.player, 50);