I want in my game to make enemies be removed when they are at a specific distance form player and then to be added again if player gets close to their spawning points(exact same thing like in kirby games with spawning enemies).Also im using ogmo for the map.In this case i made this code :
private function respawnEnemies(mapXML:XML):void
{
var node:XML;
if (whereTele == "UpDown") {//if map is wide
if (blueNR != 0) {//if this type of enemy exist in this map
var blueE:EnemyBlue;
var enemyX:Number = 0;
for each (node in mapXML.Entities.Blue)
{
//getting enemy's x
enemyX = int(node.@x);
//checking if he is in the spawning position
if ((enemyX > camera.x + 650 && enemyX < camera.x + 690) || (enemyX < camera.x - 50 && enemyX > camera.x - 100)) {
//checking if the enemy exist allready
blueE = getInstance(String(node.@myname));
if (blueE == null) {
//adding it
add(new EnemyBlue(int(node.@x), int(node.@y), String(node.@myname)));
}
}
}
}
}
else {//if map is from not wide(obviously)
//the enemyes will be spawned using y coordinate not x to decide when
}
}
My question is: Is there any other more efficient way of doing this? thx