loadin Do…

一条只能往前走的路,叫时光.

首页 联系 订阅 管理
看到一个不错的遮挡实现方案,避免了使用深度排序带来的效率问题,很好。如下:
Shadow1 Girl分别为遮挡物和人物
var shadow1:Shadow1 = new Shadow1();
var girl:Girl = new Girl();

var bs:BitmapData = new BitmapData(shadow1.width, shadow1.height, true, 0x00000000);
bs.draw(shadow1);

var bg:BitmapData = new BitmapData(girl.width, girl.height, true, 0x00000000);
bg.draw(girl);


var rect:Rectangle = new Rectangle(0, 0, bg.width, bg.height);
var pt:Point = new Point(0, 0);

var filter:BitmapData = new BitmapData(bg.width, bg.height);

var bsm:Bitmap = new Bitmap(bs);
addChild(bsm);

var bgm:Bitmap = new Bitmap(bg.clone());
addChild(bgm);


stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoving);
function onMouseMoving(event:MouseEvent):void
{
    // move bmp2 to the mouse position (centered).
    bgm.x = mouseX - 20;
    bgm.y = mouseY - 50;

    var rect2:Rectangle = new Rectangle(bgm.x, bgm.y, bg.width, bg.height);
    
    filter.fillRect(rect,  0xFFFF0000);
    //filter.threshold(bs, rect2, pt, ">", 0x00000000, 0x00000000);    //所有不透明的点变为透明
    filter.threshold(bs, rect2, pt, ">", 0x00000000, 0x00000000);  //半透明的

    //bgm.bitmapData = filter;
    bgm.bitmapData.copyPixels(bg, rect, pt, filter, pt, false);    
}
posted on 2009-08-06 11:30  i'am sl  阅读(764)  评论(0编辑  收藏  举报