tink博客上的一个碰撞检测类,思路是:用flash自带的hitTestObject预判断,再基于像素重叠检测碰撞。
原文链接:http://www.tink.ws/blog/as-30-hittest
代码如下:package ws.tink.display
{
importflash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
public class HitTest
{
public static function complexHitTestObject( target1:DisplayObject,target2:DisplayObject, accurracy:Number = 1):Boolean
{
return complexIntersectionRectangle( target1, target2, accurracy).width != 0;
}
public static function intersectionRectangle(target1:DisplayObject, target2:DisplayObject ):Rectangle
{
// If either of the items don't have a reference to stage, thenthey are not in a display list