View Full Version : positioning mcs on the stage

01-17-2009, 11:37 AM
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 ?

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++) {


01-17-2009, 12:23 PM
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.

01-17-2009, 08:18 PM
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 ?

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++) {


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum