Search code examples
actionscript-3flashactionscriptcollision-detection

How do I make my hitTestObject() more precise?


I'm doing some collision detection with a circle and a square and whenever the circle comes in contact with the square it bounces away changing its X coordinate by *-1. However, the Hit Area of the circle is a square, so even when it collides with the white area around the circle , the affect still occurs.

My question is, is there a way to modify the hit area to closer resemble my circle?

Thanks


Solution

  • Bitmap hit testing is pixel based (instead of boundary-based, like Sprite-based hit testing), so it is inherently more precise.

    Here are the Adobe docs on it.

    Here is a nice tutorial on it.

    And here is a nice code snippet on it:

    if (firstObjectBitmapData.hitTest(new Point(firstObject.x, firstObject.y), 255, secondObjectBitmapData, new Point(secondObject.x, secondObject.y), 255))
    {
        trace("hit!");
    }