2

I want to know the actual hit point when the dash line is hitting to the triangle object.

I am using the following codes for hit between two object :

target.hitTestObject(border);

where target is the triangle object and border is a group where I placed a rectangle with stroke SolidColorDash.

And I am using the following codes for getting the hit coordinate :

var x:Number = target.x;
var y:Number = target.y;

And it is giving the x and y coordinate when the dash line is touching to the boundary of the triangle object but I want the coordinate when dash line will touch the bitmapdata of the triangle object.

enter image description here

So Anybody have an idea how to resolve this issue or how to get the hit coordinate.

Babu
  • 440
  • 5
  • 23
  • 2
    Check for pixel-perfect collision libraries, some of them night have this implemented. – Vesper Jul 19 '16 at 12:57
  • Possible duplicate of [HitTest not working correctly when using Graphics.lineTo/curveTo](http://stackoverflow.com/questions/21923615/hittest-not-working-correctly-when-using-graphics-lineto-curveto) – null Jul 19 '16 at 18:40
  • Thanks @Vesper pixel-perfect collision solve my problem. – Babu Jul 20 '16 at 10:15

1 Answers1

1

The Following Codes Solve my Problem for getting real collision:

private var returnValue:Boolean;
private var firstPoint:Point;
private var secondPoint:Point;
private var firstRectangle:Rectangle;
private var secondRectangle:Rectangle;
private var firstObjectBmpData:BitmapData;
private var secondObjectBmpData:BitmapData;
private var firstOffSetMatrix:Matrix;
private var secondOffSetMatrix:Matrix;

public function testCollision(clip1:DisplayObjectContainer, clip2:DisplayObjectContainer):Boolean
{
        returnValue = false;

        firstRectangle = clip1.getBounds(clip1);
        secondRectangle = clip2.getBounds(clip2);

        if(secondRectangle.width != 0 && secondRectangle.height != 0 && firstRectangle.width != 0 && firstRectangle.height != 0)
        {
            firstObjectBmpData = new BitmapData(firstRectangle.width, firstRectangle.height, true, 0);
            firstObjectBmpData.draw(clip1);

            secondObjectBmpData = new BitmapData(secondRectangle.width, secondRectangle.height, true, 0);
            secondObjectBmpData.draw(clip2);

            firstPoint = new Point(clip1.x, clip1.y)
            secondPoint =  new Point(clip2.x, clip2.y)

            if (firstObjectBmpData.hitTest(firstPoint, 255, secondObjectBmpData, secondPoint, 255))
            {
                returnValue = true;
            }
        }

        return returnValue;
}
Babu
  • 440
  • 5
  • 23