[Flashcoders] Collision detection NOT using hitTest()

2007-02-23 Thread Jeff Fox

Hey gang,
I have a map movie that needs to test whether two near objects will overlap
one another BEFORE I actually instantiate and draw the movie clip, so I need
a good object collision test that does not use hitTest(). I have a set of x
and y and size properties for each object that I use to place them when
they're created, but what I want to do is if the objects will overlap at any
point, merge them into a single object.

Here's an example of what I need to catch:

Point A Los Angeles (x: 150, y: 99, size: 8 pixels)
Point B: San Diego (x: 153, y: 103, size: 8 pixels)

When drawn, the LA dot and San Diego dot will overlap a little and therefore
cause a problem rendering pop-up content, so I want to merge them. What I
need is a reliable check to see if that happens. Right now I'm using:

var uLeftX:Number = cityA._x - 2;
var lRightX:Number = (cityA._x + _size) +2;
var uLefttY:Number = cityA._y - 2;
var lRightY:Number = (cityA._y + _size) +2;

if (mapObjects.length  1) {
   for (var mo:Number = 0; mo  mapObjects.length; mo++) {
   // GET VISIBLE AREA OF CURRENT MAP OBJECT
   var tmpULeftX:Number = parseInt(mapObjects[mo]._x) - 2;
   var tmplRightX:Number = (parseInt(mapObjects[mo]._x) + _dotSize) +2;

   var tmpuLeftY:Number = parseInt(mapObjects[mo]._y) - 2;
   var tmplRightY:Number = (parseInt(mapObjects[mo]._y) + _dotSize) +2;
   if ((uLeftX  tmpULeftX  uLeftX  tmplRightX)  (uLefttY 
tmpuLeftY  uLefttY  tmplRightY)) {
   trace(Dot collision occures between  + cityA.cityName +  and
 + mapObjects[mo].cityName);
   }
   } // END for
} // END if

The above script DOES detect collisions, but not between the LA and San
Deigo properties listed above. Can anyone see a flaw in the line that tests
the overlap?

-Jeff
--
Jeff Fox
[EMAIL PROTECTED]

--
Jeff Fox
[EMAIL PROTECTED]
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Collision detection NOT using hitTest()

2007-02-23 Thread T. Michael Keesey

Look into flash.geom.Rectangle, specifically the intersects(Rectangle) method.

On 2/23/07, Jeff Fox [EMAIL PROTECTED] wrote:

Hey gang,
I have a map movie that needs to test whether two near objects will overlap
one another BEFORE I actually instantiate and draw the movie clip, so I need
a good object collision test that does not use hitTest(). I have a set of x
and y and size properties for each object that I use to place them when
they're created, but what I want to do is if the objects will overlap at any
point, merge them into a single object.

Here's an example of what I need to catch:

Point A Los Angeles (x: 150, y: 99, size: 8 pixels)
Point B: San Diego (x: 153, y: 103, size: 8 pixels)

When drawn, the LA dot and San Diego dot will overlap a little and therefore
cause a problem rendering pop-up content, so I want to merge them. What I
need is a reliable check to see if that happens. Right now I'm using:

var uLeftX:Number = cityA._x - 2;
var lRightX:Number = (cityA._x + _size) +2;
var uLefttY:Number = cityA._y - 2;
var lRightY:Number = (cityA._y + _size) +2;

if (mapObjects.length  1) {
for (var mo:Number = 0; mo  mapObjects.length; mo++) {
// GET VISIBLE AREA OF CURRENT MAP OBJECT
var tmpULeftX:Number = parseInt(mapObjects[mo]._x) - 2;
var tmplRightX:Number = (parseInt(mapObjects[mo]._x) + _dotSize) +2;

var tmpuLeftY:Number = parseInt(mapObjects[mo]._y) - 2;
var tmplRightY:Number = (parseInt(mapObjects[mo]._y) + _dotSize) +2;
if ((uLeftX  tmpULeftX  uLeftX  tmplRightX)  (uLefttY 
tmpuLeftY  uLefttY  tmplRightY)) {
trace(Dot collision occures between  + cityA.cityName +  and
 + mapObjects[mo].cityName);
}
} // END for
} // END if

The above script DOES detect collisions, but not between the LA and San
Deigo properties listed above. Can anyone see a flaw in the line that tests
the overlap?

-Jeff
--
Jeff Fox
[EMAIL PROTECTED]

--
Jeff Fox
[EMAIL PROTECTED]
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com




--
T. Michael Keesey
Director of Technology
Exopolis, Inc.
2894 Rowena Avenue Ste. B
Los Angeles, California 90039
--
The Dinosauricon: http://dino.lm.com
Parry  Carney: http://parryandcarney.com
ISPN Forum: http://www.phylonames.org/forum/
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com