Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collision detection on multiple objects

Status
Not open for further replies.

gs0uL

ISP
Nov 18, 2003
1
AU
I am working on a flash movie for a friend of mine that utilises random movement etc. The idea is that a number of objects randomly appear on the screen. There are three different types of objects, and I need 4 of each object to appear in a random location. After these items are on the screen, another object randomly moves around the screen and destroys them.

I need to create the initial random objects into some kind of array so I dont have to do a collision detection on every item. I have -NO- idea how to do this. secondly, when the large object collides with the smaller ones, the smaller one dissapears. Ideally once the objects have all been destroyed, ie when the array reaches 0, a whole new set of objects will appear.

Have a look at the movie below and you'll see what I mean. Its only small.

The movie and source code are available here:

Im really stuck with this, my background is in graphic design and coldfusion programming, so I'm finding actionscript fairly difficult. Please help!

__________________
Aaron
 
If you have the objects on stage already, named sequentially object 0 thru object 11, this will work:

Code:
//put clips in array
clipsArray = [];
for (var i = 0; i<12; i++) {
	clipsArray.push(this['object'+i]);
}
//check for large object hitting small object
doHitChecking = function (count) {
	clip = clipsArray[count];
	if (largeObject.hitTest(clip)) {
		// remove small object when hit
		clip._visible = 0;
		clipsArray.splice(count, 1);
	}
};
this.onEnterFrame = function() {
	//check for collisions
	for (var i = 0; i<clipsArray.length; i++) {
		doHitChecking(i);
	}
};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top