2

使用brush_mc,您可以刷过一个蒙版,这会将像素在画笔描边中变为透明。所以在视觉上它会擦除蒙版,并出现蒙版的影片剪辑。我想追踪,如果面具完全变成透明。

是否可以在没有位图数据的情况下检查蒙版是否完全透明?

// this creates a mask that hides the movieclip on top
var mask_mc:MovieClip = new MovieClip();
addChild(mask_mc)

//assign the mask to the movieclip it should 'cover'
mc1.mask = mask_mc;

//add event listeners for the 'brush'
brush_mc.addEventListener(MouseEvent.MOUSE_DOWN,brushDown);
brush_mc.addEventListener(MouseEvent.MOUSE_UP,brushUp);

//function to drag the brush over the mask
function brushDown(dragging:MouseEvent):void{
    dragging.currentTarget.startDrag();
    MovieClip(dragging.currentTarget).addEventListener(Event.ENTER_FRAME,erase) ;
    mask_mc.graphics.moveTo(brush_mc.x,brush_mc.y);
}

//function to stop dragging the brush over the mask
function brushUp(dragging:MouseEvent):void{
    dragging.currentTarget.stopDrag();
    MovieClip(dragging.currentTarget).removeEventListener(Event.ENTER_FRAME,erase);
}

//fill the mask with transparant pixels so the movieclip turns visible
function erase(e:Event):void{
    with(mask_mc.graphics){
        beginFill(0x000000);
        drawRect(brush_mc.x,brush_mc.y,brush_mc.width,brush_mc.height);
        endFill(); 
    }
}
4

2 回答 2

2

这里看看比较功能。
您需要做的是创建第二个位图数据对象,其大小与您的掩码相同,但具有完全透明的 0x00000000。然后使用比较功能。正如文档所说。

如果 BitmapData 对象是等效的(具有相同的宽度、高度和相同的像素值),则该方法返回数字 0。

[编辑]

var myTestingBitmapData:BitmapData = new BitmapData(mask_mc.width, mask_mc.height, true, 0x00000000);

// this is untested code but you might have to comvert mask_mc to bitmapdata
trace( myTestingBitmapData.compare( mask_mc) )
于 2011-09-06T21:50:41.030 回答
0

您可能可以实现某种形式的计数器来跟踪掩码的状态。

这个想法是在刷动作之前检查蒙版的状态。您有一个总像素数,然后根据像素的颜色从计数器中添加或减去。

当您的计数器达到某个值时,您的掩码将被擦除。

这不是一个理想的解决方案,因为您的蒙版可能看起来已经被擦除了,但是您仍然有一些随机像素使计数器保持在必要的值以下,因此您可能需要平均一点……是否使用画笔行动或与柜台。

于 2011-09-07T01:46:56.080 回答