Hey guys, I am having a bit of trouble creating enemies at random points on my map, I want them to be contained within a certain y-axis range, I have made this code and it randomly generates then overwrites endless instances of the enemy sprite within the range. HELP!
//Loop:
public function spawnbarb(event:Event):void
{
var rand:int = 350;
for(var count:int = 0; count <= 2; count++)
{
if(rand != barb.y)
{
barb.x = 400;
rand = Math.floor(Math.random() * 200 + 225); //Learn how to generate a new random number each iteration of the loop.
barb.y = rand;
stage.addChild(barb);
barb.name = "barb" + count;
trace("barb.name = "+ barb.name);trace("rand = " + rand); trace ("barb.y = " + barb.y);
}
else if(rand == barb.y)
{
rand = rand = Math.floor(Math.random() * 295 + 255);
trace("rand in while = " + rand)
}
}