hi everybody,
I am randomly placing several display objects on stage using a for loop.
My problem is that sometimes they overlap and i need to avoid this.
While is pretty simple to check two given objects for collision using sprite1.hitTestObject(sprite2), i am wondering how can i test several instances at the same time.
i think the logical thing is creating other loops and place my objects into an array but can’t make it to work
the code looks like this:
[COLOR=DarkRed]
var cont:Sprite = new Sprite();
addChild(cont);
cont.x = stage.stageWidth /2;
cont.y = stage.stageHeight /2;
for (var i:uint = 10; i>0; i–) {
var sp:Sprite = new Sprite();
sp.graphics.beginFill(Math.random() * 0xFFFFFF);
sp.graphics.drawRect(0,0,50,50);
sp.x=Math.random()*300-300;
sp.y=Math.random()*300-300;
sp.alpha=.7;
cont.addChild(sp);
/*
* if (the sprites overlap)
* {
* move the sprites to a new position
* }
*/
}
[/COLOR]
any help would be appreciated. thank you