如何测试具有透明背景的Sprite
和Bitmap
图像之间的碰撞?
我看起来尽可能多,因为这不起作用,但我找不到。
我预期无效的碰撞位于名为BridgeCollision
请帮帮忙?
var bridgeSpriteArr:Array = new Array(bridgeArr.length);
var bridge_BMArr:Array = new Array(bridgeArr.length);
for ( var i:int = 0; i < bridgeArr.length; i++)
{
var bridgeSprite:Sprite = new Sprite();
bridgeSprite.graphics.lineStyle(4, 0x00ff00);
bridgeSprite.graphics.moveTo(bridgeArr[i].x, bridgeArr[i].y);
switch (bridgeArr[i].nVector)
{
case 0:
bridgeSprite.graphics.lineTo(bridgeArr[i].x, bridgeArr[i].y + bridgeArr[i].maxRange);
break;
case 1:
bridgeSprite.graphics.lineTo(bridgeArr[i].x - bridgeArr[i].maxRange, bridgeArr[i].y);
break;
case 2:
bridgeSprite.graphics.lineTo(bridgeArr[i].x, bridgeArr[i].y - bridgeArr[i].maxRange);
break;
case 3:
bridgeSprite.graphics.lineTo(bridgeArr[i].x + bridgeArr[i].maxRange, bridgeArr[i].y);
break;
}
var bridge_BMD:BitmapData = new BitmapData(bridgeSprite.width, bridgeSprite.height,true,0);
var bridgeBounds:Rectangle = bridgeSprite.getBounds(bridgeSprite);
var m:Matrix = new Matrix();
m.translate(-bridgeBounds.x, -bridgeBounds.y);
bridge_BMD.draw(bridgeSprite, m);
var bridge_BM:Bitmap = new Bitmap(bridge_BMD);
bridge_BMArr[i] = bridge_BM;
bridgeSpriteArr[i] = bridgeSprite;
Main.getStage().addChild(bridgeSprite);
}
var bridgeCollision:Boolean = false;
var shipCollision:Boolean = false;
Main.getStage().addEventListener( Event.ENTER_FRAME,
function bridgeCollision(e:Event):void
{
bridgeCollision = false;
for (var i:int = 0; i < bridgeSpriteArr.length; i++)
{
if ( object1.hitTestObject(bridgeSpriteArr[i]))
{
trace("hit bridge - trans");
if (object1_BMD.hitTest(new Point(object1.x, object1.y), 255, bridge_BMArr[i].bitmapData,
new Point(bridgeSpriteArr[i].x, bridgeSpriteArr[i].y),0)) // this is the collision with the problem
{
trace("hit bridge - visible");
bridgeCollision = true;
}
}
}
});