2007/06/21 | AS3 倒影算法
类别(AS3) | 评论(6) | 阅读(1767) | 发表于 23:18

由于在RIA开发中需要对有水的地图场景做一些特效处理比如说倒影,如下图的效果:

至于RIA:请访问 q.uen.cn/ria/ria.html


因此,分享一下倒影算法的心得,首先观察倒影的特点如下
1,是上下反转的图像
2,从上到下透明度越来越大
那么我来完成这2步操作:

function createRef(p_source:DisplayObject):void{
   //对源显示对象做上下反转处理
    var bd:BitmapData=new BitmapData(p_source.width,p_source.height,true,0);
    var mtx:Matrix=new Matrix();
    mtx.d=-1;mtx.ty=bd.height;
    bd.draw(p_source,mtx);
//生成一个渐变遮罩
    var width:int=bd.width;
    var height:int=bd.height;
    mtx=new Matrix();
    mtx.createGradientBox(width,height,0.5 * Math.PI);
    var shape:Shape = new Shape();
    shape.graphics.beginGradientFill(GradientType.LINEAR,[0,0],[0.9,0.2],[0,0xFF],mtx)
    shape.graphics.drawRect(0,0,width,height);
    shape.graphics.endFill();
    var mask_bd:BitmapData=new BitmapData(width,height,true,0);
    mask_bd.draw(shape);
//生成最终效果
    bd.copyPixels(bd,bd.rect,new Point(0,0),mask_bd,new Point(0,0),false);
//将倒影位图放在源显示对象下面
    var ref:Bitmap=new Bitmap();
    ref.y=p_source.height;
    ref.bitmapData=bd;
    p_source.parent.addChild(ref);
}
源显示对象如图

生成的倒影效果

 

 

 

如看不到SWF,请看下面截图

 

当然你也可以加入一些水波效果以达到更COOL的效果

0

评论Comments

日志分类
首页[33]
AS3[20]
工作日记[10]
个人简介[2]
ASV[1]