首页 > 代码库 > 显示对象的像素级碰撞检测

显示对象的像素级碰撞检测

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);


stage.addEventListener(Event.ENTER_FRAME,frameFunc);

function frameFunc(e:Event):void{

mc1.x=this.mouseX;

mc1.y=this.mouseY;

if(bmd1.hitTest(new Point(mc1.x, mc1.y), 0x55, bmd2, new Point(mc2.x, mc2.y))){

mc2.gotoAndStop(2);

}else{

mc2.gotoAndStop(1);

}

}