hitTest question 2004-03-18 - By Andreas Weber
Back Hi Jason
Before I forget: would you mind turning off the setting in your e-mail client which prompts all of us to send you a confirmation that we received your message. Thanks!
Your approach is correct - you'll even need a nested loop to check each clip against each other one. Something like
clips = [A_mc, B_mc, C_mc];
this.onEnterFrame = function(){ for(i=0, len1=clips.length; i<len1;i++){ for(j=0, len2=clips.length; j<len1;j++){ if(i != j){ res = clips[i].hitTest(clips[j]); trace(res); } } } }
(will make some redundant double-checks. But inserting a complicated if...else structure will probably not make it any faster)
Be aware that this is highly processor intense and will bog down the computer if you have many clips. Another point to keep in mind: this form of hitTest() only tests wether the bounding boxes of two clips intersect - it does not test wether the shapes within the bounding boxes overlap.
Strange...
Are nested while loops not supported by Flash?
Does anyone see why this gives a time-out? (the loop counters don't stop at zero, they go on decrementing)
clips = [A_mc, B_mc, C_mc];
this.onEnterFrame = function(){ var i = clips.length; var j = i;
while(i--){ while(j--){ if(i != j){ res = clips[i].hitTest(clips[j]); trace(res); } } } }
-- ---- ------ Andreas Weber motiondraw.com
-- --Original Message-- -- From: Jason Merrique [mailto:j.merrique@(protected)] Sent: Thursday, March 18, 2004 1:14 PM To: flashnewbie@(protected) Subject: RE: [Flashnewbie] hitTest question
Oops, forgot something:
As a workaround, I had planned to put all the relevant mc's into an array, and then cycle through the array doing a hitTest with each mc. I'm sure there's a more efficient way though....
Cheers
Json
From: Jason Merrique [mailto:j.merrique@(protected)] Sent: 18 March 2004 12:12 To: flashnewbie@(protected) Subject: [Flashnewbie] hitTest question
Hi Chaps,
I've got a quick question:
MovieClip.hitTest()
Does the target need to be specific? i.e. Is it possible to have this return true if MovieClip collides with *anything*?
The reason for asking is that I've created a movie in which lots of objects are moving around (randomly) and I don't want them to overlap.
Thanks in advance!
Jason
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ Supported by Fig Leaf Software -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ Lower Prices for Certified Training! Check out new lower prices for Certified Macromedia Training from Fig Leaf Software. Expand your skill set with courses in ColdFusion, Flash, Rich Internet Applications and .NET in the new year. Fig Leaf Software provides the highest caliber instruction at our training centers in Washington D.C., Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location.
Get the details at http://training.figleaf.com/ -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- To unsubscribe, e-mail: flashnewbie-unsubscribe@(protected) For additional commands, e-mail: flashnewbie-help@(protected)
|
|