Good Day dear Reader,
I am creating new Enemies by triggering a Tile Collision(createEnemies gets called) this works fine but i have 3Types of Enemy and thats wehre i struggle:
how can i set attributes when creating an Enemie? this is how i create Enemies:
this.enemiesObj = this.physics.add.group({
classType: Enemies
});
createEnemies(){
this.objectLayer.objects.forEach(obj =>{
switch(obj.type){
case "enemies":
let dist = Phaser.Math.Distance.BetweenPoints(player,obj)
if(dist <= 550){
switch(obj.name){
case "skelett":
this.enemiesObj.get(obj.x+obj.width*0.5,obj.y-obj.height*0.5,"skelett",0,1,1).setSize(32, 40).setOffset(16, 12);
break;
case "skelett-stark":
this.enemiesObj.get(obj.x+obj.width*0.5,obj.y-obj.height*0.5,"skelett",0,1,1).setSize(32, 40).setOffset(16, 12);
/*
How Can i Set For Example enemie.Health = 50 when creating it?
*/
break;
case "skelett-boss":
this.enemiesObj.get(obj.x+obj.width*0.5,obj.y-obj.height*0.5,"skelett",0,1,1).setSize(32, 40).setOffset(16, 12);
/*
How Can i Set For Example enemie.Health = 100 ?
*/
break;
}
}
break;
}
})
}
Do i need to creat a new Class and Extend the Class Enemy but how…? Man i have no clue
I am very new to Phaser but i realy love it!
Thanks for any Help!
NetForce