Instance creation problem
Hi guys
I'm having trouble creating instances of an object, I want a random number to be generated and then based on the number which was choosen create an instance of an object in one of four positions.
The problem I'm having is, my instances are generated fine but there is one that keeps jumping to x 0 and y 0.
Please help!
Code:
//Enemy Creation
if ( Math.random()<0.01 )
{
var randomX:Number = Math.random()*400;
var newEnemy = new Enemy(x,y);
if (randomX<101)
{
new Enemy(x,y);
army.push(newEnemy);
addChild(newEnemy);
enemy.x=50;
enemy.y=-50;
}
if (randomX>100 && randomX<201)
{
new Enemy(x,y);
army.push(newEnemy);
addChild(newEnemy);
enemy.x=150;
enemy.y=-50;
}
if (randomX>200 && randomX<301)
{
new Enemy(x,y);
army.push(newEnemy);
addChild(newEnemy);
enemy.x=250;
enemy.y=-50;
}
if (randomX>300 && randomX<401)
{
new Enemy(x,y);
army.push(newEnemy);
addChild(newEnemy);
enemy.x=350;
enemy.y=-50;
}
}