all groups > flash (macromedia) > january 2005 >
You're in the

flash (macromedia)

group:

Collision detection on load



Collision detection on load Slackernaut
1/12/2005 10:17:39 PM
flash (macromedia): I would like to randomly _x,_y populate the stage with randomly sized movie
clips at random intervals but don't want them to obscure each other. How do I
tell the mc on loading, that the space is occupied/free and that it has to
move or its OK. Ive got the random part but I am missing the understanding of
the hit test part. Thanks so much.
Re: Collision detection on load chrispowers
1/13/2005 12:24:57 AM
Slackernaut, I tried it out, see if this helps
http://www.rockgospel.com/RandomBox.fla. I used a 'for' loop to do the hit
testing. If you wanted them all to spawn at the same time, you could use
another for loop instead of the enterFrame. Hope it helps, Chris Powers
Re: Collision detection on load NSurveyor
1/13/2005 12:30:49 AM
Here's a sample script:

mcArray = ['b','b','b'];
//^Put clip's linkage identifiers in this array ^
deleteAfter = 2500;
//^If a movieclip is still positioned over another movieclip after the
specified
// attemps, then, the movieclip will be discluded^
createEmptyMovieClip('randomClips',getNextHighestDepth());
for(i=0;i<mcArray.length;i++){
removeClip = false;
test = attachMovie(mcArray,'test_mc'+i,getNextHighestDepth());
count = 0;
test._x = random(Stage.width);
test._y = random(Stage.height);
while(test.hitTest(randomClips)){
count++;
test._x = random(Stage.width);
test._y = random(Stage.height);
if(count>deleteAfter ){
trace(mcArray+' took too long to load. It will be deleted...')
removeClip = true;
break;
}
}
if(!removeClip){
cmc =
randomClips.attachMovie(mcArray,'mc_'+i,randomClips.getNextHighestDepth());
cmc._x = test._x;
cmc._y = test._y;
}
removeMovieClip(test);
}
Re: Collision detection on load NSurveyor
1/13/2005 12:32:18 AM
Whoops, shouldn't have used that damn [ i ]

Here's my script:

Here's a sample script:

mcArray = ['b','b','b'];
//^Put clip's linkage identifiers in this array ^
deleteAfter = 2500;
//^If a movieclip is still positioned over another movieclip after the
specified
// attemps, then, the movieclip will be discluded^
createEmptyMovieClip('randomClips',getNextHighestDepth());
for(i=0;i<mcArray.length;i++){
removeClip = false;
test = attachMovie(mcArray[ i ],'test_mc'+i,getNextHighestDepth());
count = 0;
test._x = random(Stage.width);
test._y = random(Stage.height);
while(test.hitTest(randomClips)){
count++;
test._x = random(Stage.width);
test._y = random(Stage.height);
if(count>deleteAfter ){
trace(mcArray[ i ]+' took too long to load. It will be deleted...')
removeClip = true;
break;
}
}
if(!removeClip){
cmc = randomClips.attachMovie(mcArray[ i
],'mc_'+i,randomClips.getNextHighestDepth());
cmc._x = test._x;
cmc._y = test._y;
}
removeMovieClip(test);
}
AddThis Social Bookmark Button