本页面由 Flash 保存计划 从 Internet Archive 存档还原 · 快照 2011-03-09 · 原址 http://www.flash8.net/teach/6451.htm ← Flash 保存计划

AS3 倒影算法

作者:云开   类型:转载   来源:云开之RIA开发

  

由于在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的效果。

   责任编辑:silvia    时间:2007年9月26日
  • 最近更新