somebody621 -> RE: Flash Q&A thread 2 ** checked everyday (4/3/2006 19:57:12)
|
That's easy.
stageheight = Stage.height+1;
//+ 1 just for random positions
stagewidth = Stage.width+1;
enemynum=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
//fifteen enemies: The number is stored in an array
for(var i in enemynum){
//every time the loop passes through a number in an array; starts from 0
duplicateMovieClip("enemy", "enemy"+i, i + 1000);
var enemy = _root["enemy" + i];
//just basicly rename the enemy for quick access
//duplicate the enemy movie clip. It's new name would be enemy + i(say i was 0, enemy name would be enemy0),
// depth(how close it is to you) is i + 1000(do the math)
ob.zpos = int(Math.random()*(stageheight)-0.01);
//Math.random() returns a number between 1 and 0 randomly. int rounds down like Math.floor, but is faster.
ob._y = ob.zpos;
//declare the x of ob. This, of course is assuming that the enemy drawing is in the middle of the movie clip
ob.swapDepths(ob.zpos+1000);
//swaps the depth depending on the enemy's y position. closer the enemy, higher the depth
ob.xpos = it(Math.random()*(stagewidth)-0.01);
//the random x position
}
Note: I've on purposely left stuff out and made mistakes to make you actually read the code and understand it. NO COPY AND PASTERS! Also, give credit if you use my code or manipulate it. If you write your own, it's yours, however.
|
|
|
|