I want to create a function that can create enemies that behave the same but they are in different x and y positions. I feel I am overthinking it. this is my previous attempt that did not work because the console says the enemy parameter is undefined after the first frame.
//creating the functions for the enemies
//grass monster functions
const createGrassMonster = (xPosition, yPosition, enemy) => {
if (start == true) //start is equal to true only if it is the first frame of the game
{
enemy = this.physics.add.sprite(xPosition, yPosition, 'wood');
this.physics.add.collider(enemy, this.player);
}
//here is the part where you would move the enemy
//or things you would normally do in the update function
}
window.setInterval(createGrassMonster, 1);
//this line of code above calls the function on repeat
//this is where I call my function for the enemy
// wont work if it is in the update function
createGrassMonster(100, 100, this.woodMonster);
createGrassMonster(20, 20, this.woodMonster2);