View Full Version : Random disposing Items...
log
July 31st, 2007, 01:19 PM
how i can random dispose items on my stage, avoiding the overlap between them?
this is my easey concept. But i Obtain overlap in some case.
var mcs:Array = new Array();
for (var i:int = 0; i < 10; i++) {
var sp:Sprite = new Sprite();
sp.name = "mc" + i;
sp.y = Math.random()*stage.stageHeight
sp.x = Math.random()*stage.stageWidth
var rscale:Number = 0.6+Math.random()*0.35;
sp.scaleX=rscale;
sp.scaleY=rscale;
addChild(sp);
mcs.push(sp);
}
GrndMasterFlash
July 31st, 2007, 01:49 PM
make an array and add then new random loc every time, then on next creation check it against the array values, and you might do somthing like arrayX + 50, arrayY + 50
dig? :drool:
log
July 31st, 2007, 02:43 PM
make an array and add then new random loc every time, then on next creation check it against the array values, and you might do somthing like arrayX + 50, arrayY + 50
dig? :drool:
thanks. do u have an pretty example how to work?
GrndMasterFlash
August 1st, 2007, 10:45 AM
thanks. do u have an pretty example how to work?
var mcs:Array = new Array();
//contain all gotten space
var usedY:Array = new Array();
var usedX:Array = new Array();
function getloc(){
sp.y = Math.random()*stage.stageHeight
sp.x = Math.random()*stage.stageWidth
//add the new value to the used array
if((sp.y != usedY[])&&(sp.x != usedX[])){
usedY.push(sp.y)
usedX.push(sp.x)
}else{
getloc.call()
}
//yer stuff again
for (var i:int = 0; i < 10; i++) {
var sp:Sprite = new Sprite();
sp.name = "mc" + i;
//your placement used to be here
getloc.call()
//:P
var rscale:Number = 0.6+Math.random()*0.35;
sp.scaleX=rscale;
sp.scaleY=rscale;
addChild(sp);
mcs.push(sp);
}
you'll probaly have to work with this to make it work right,
and the function syntax is in AS2 cause im still learning
AS3 but i hope this gives you a better idea.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.