...

View Full Version : positioning mcs on the stage



gencoglu
01-17-2009, 10:37 AM
:confused:Hi,
I have 20 rectangle shaped movie clips.m1,m2,m3,...m20,I want to display only 5 of them randomly.and the NCs should be unique(no dublications) need to change their _y position randomly everytime clciking a button..but there must be 10px space between them... so how do I modify the code to do it ?
thanks

myArray = new Array(m1, m2, m3, m4, m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15,m16,m17,m18,m19,m20);

for (i=0; i<=myArray.length; i++) {
_root["m"+i]._x=400;
_root["m"+i]._y=Math.floor(Math.random()*300)+20;


}

gnomeontherun
01-17-2009, 11:23 AM
That would require a little more work. I don't have the time to actually make the calculations or functions, but here is an idea of the logic.

You would need to first change your for loop to only display 5, right now it places all 20.

You need to make a function that will take the current position of an element, and check if it is within 10px of any other. If not then it places the element, if it does want to place something too close, then you need to have it rerun the function to get a new random place.

gencoglu
01-17-2009, 07:18 PM
Hi,
Now I can craete a random movement for the MCs
but there is always a space in between which is more than 20px...any idea ?



on(Press){
n = 6;
ary = [];
for (var i = 0; i < n; ++i) ary[i] = i;
ary.sort( function() { return random(2)? 1 :-1; });

var bir = new Array(m1, m2, m3, m4, m5);
var hedef = new Array(h1, h2, h3, h4, h5);
var say=0;
for (z=0; z<=bir.length; z++) {
_root["m"+z]._x=500;
_root["m"+z]._y=(ary[z]*50)+40;
_root.kutu.text=ary;
}

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum