Flash ActionScript 3.0光线-形状相交

Flash ActionScript 3.0光线-形状相交,flash,actionscript-3,collision-detection,intersection,Flash,Actionscript 3,Collision Detection,Intersection,给定包含从库中加载的矢量形状的MovieClip-是否有方法检查从点X1、y2到点X2、y2的直线是否与该形状相交?这实际上取决于形状。如果它是一个简单的几何形状,或者您可以使用一个进行碰撞,那么您可以使用网络上数百种光线/形状碰撞方法中的一种 如果它是一个非常特殊的形状,那么你可以做的一件事就是沿着你的光线,在你的形状上进行hitTestPoint调用。大概是这样的: var ray:Point = new Point( x2 - x1, y2 - y1 ); // get the ray

给定包含从库中加载的矢量形状的MovieClip-是否有方法检查从点X1、y2到点X2、y2的直线是否与该形状相交?

这实际上取决于形状。如果它是一个简单的几何形状,或者您可以使用一个进行碰撞,那么您可以使用网络上数百种光线/形状碰撞方法中的一种

如果它是一个非常特殊的形状,那么你可以做的一件事就是沿着你的光线,在你的形状上进行hitTestPoint调用。大概是这样的:

var ray:Point = new Point( x2 - x1, y2 - y1 ); // get the ray

// we want to check in, say 10 steps. depending on the length of the ray, you can increase/decrease this
var steps:int = 10;

// scale the ray
ray.x /= steps;
ray.y /= steps;

// step along the ray
var start:Point = new Point( x1, y1 );
for( var i:int = 0; i < steps; i++ )
{
    // hit test against the shape
    if( myShape.hitTestPoint( start.x, start.y, true ) )
    {
        // it's intersecting, do something
        break;
    }

    // it didn't intersect, keep going
    start.x += ray.x;
    start.y += ray.y;
}

是的,这是一个特定的形状。我还能算出确切的交点吗?让你的步子变小,让交点代码变成一个函数,让它返回它的当前点。