# Checking for collision

**URL:** https://forum.kirupa.com/t/checking-for-collision/299393
**Category:** Uncategorized
**Created:** [November 4, 2009, 10:22am UTC](https://forum.kirupa.com/t/checking-for-collision/299393 "2009-11-04T10:22:27Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![marcellosimeone](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@marcellosimeone](https://forum.kirupa.com/u/marcellosimeone)
#### Post date: [November 4, 2009, 10:22am UTC](https://forum.kirupa.com/t/checking-for-collision/299393/1 "2009-11-04T10:22:27Z")

</div>

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
