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.
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
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); }
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); }
Don't see what you're looking for? Try a search.
|