像素级的碰撞测试

var tx, ty;
mc1.buttonMode = true;
mc1.addEventListener("mouseDown", mousedownHandler);
mc2.gotoAndStop(1);

var bmd1 = new BitmapData(mc1.width, mc1.height, true, 0);
bmd1.draw(mc1);
var bmd2 = new BitmapData(mc2.width, mc2.height, true, 0);
bmd2.draw(mc2);

function mousedownHandler(e){
 tx = e.stageX - mc1.x;
 ty = e.stageY - mc1.y;
 stage.addEventListener("mouseMove", mousemoveHandler);
 stage.addEventListener("mouseUp", mouseupHandler);
}

function mousemoveHandler(e){
 mc1.x = e.stageX - tx;
 mc1.y = e.stageY - ty;
 if(bmd1.hitTest(new Point(mc1.x, mc1.y), 0x55, bmd2, new Point(mc2.x, mc2.y))){
  mc2.gotoAndStop(2);
 }else{
  mc2.gotoAndStop(1);
 }
}

function mouseupHandler(e){
 stage.removeEventListener("mouseMove", mousemoveHandler);
 stage.removeEventListener("mouseUp", mouseupHandler);
}

你可能感兴趣的:(像素级的碰撞测试)