【发布时间】:2017-07-12 22:15:49
【问题描述】:
我无法让 bitmap hittest 方法在我的影片剪辑上正常工作。我尝试了几次使用来自不同来源的信息,但都没有奏效。我遇到了一个可以为我处理所有最常见的困惑的预制函数,我尝试使用它。我首先在一个新程序上进行了尝试,发现为了使该功能正常工作,影片剪辑必须位于左上角的中心,但考虑到我必须在我的影片剪辑上使用特定的旋转点,以左上角为中心不是一个选择。我还尝试更改偏移量的计算方式,以查看是否可以将每个偏移量操纵到左上角,但这似乎没有任何好处。
我知道这是一个非常具体的问题,但没有足够的关于位图命中测试的信息让我自己理解这一点,我认为这对于尝试使用和理解精确碰撞的其他人也可能有用。
这是预制函数的代码:
var _returnValue:Boolean;
var _onePoint:Point;
var _twoPoint:Point;
var _oneRectangle:Rectangle;
var _twoRectangle:Rectangle;
var _oneClipBmpData:BitmapData;
var _twoClipBmpData:BitmapData;
var _oneOffset:Matrix;
var _twoOffset:Matrix;
function complex(clip1:DisplayObjectContainer, clip2:DisplayObjectContainer):Boolean
{
_returnValue = false;
_twoRectangle = clip1.getBounds(clip1);
_oneOffset = clip1.transform.matrix;
_oneOffset.tx = clip1.x - clip2.x;
_oneOffset.ty = clip1.y - clip2.y;
_twoClipBmpData = new BitmapData(_twoRectangle.width, _twoRectangle.height, true, 0);
_twoClipBmpData.draw(clip1, _oneOffset);
_oneRectangle = clip2.getBounds(clip2);
_oneClipBmpData = new BitmapData(_oneRectangle.width, _oneRectangle.height, true, 0);
_twoOffset = clip2.transform.matrix;
_twoOffset.tx = clip2.x - clip2.x;
_twoOffset.ty = clip2.y - clip2.y;
_oneClipBmpData.draw(clip2, _twoOffset);
_onePoint = new Point(_oneRectangle.x, _oneRectangle.y);
_twoPoint = new Point(_twoRectangle.x, _twoRectangle.y);
if(_oneClipBmpData.hitTest(_onePoint, 255, _twoClipBmpData, _twoPoint, 255))
{
_returnValue = true;
}
_twoClipBmpData.dispose();
_oneClipBmpData.dispose();
return _returnValue;
}
下面是调用预制函数的代码:
var inVision:Boolean = complex(visionVector[controlBirds], birdVector[checkLRD]);
以下是影片的截图:
Bird movieclip (The movieclip referenced by the birdVector)
Vision movieclip (The movieclip referenced by the visionVector)
任何帮助将不胜感激。
【问题讨论】:
标签: actionscript-3 bitmap collision-detection movieclip hittest