一聚教程网:一个值得你收藏的教程网站

热门教程

as3 火燃烧效果实现代码

时间:2022-06-28 22:17:45 编辑:袖梨 来源:一聚教程网

as3 火燃烧效果实现代码

private function update(e:event):void {
target.filters = [new displacementmapfilter(bmd, new point(), bitmapdatachannel.red,bitmapdatachannel.red, 10, strengh, "clamp")];
offset=offset.add(v);
bmd.perlinnoise(size / 2, size, 3, randomseed, false, true, 1, true, [offset, offset]);
}

main.as文件代码

package
{
 import flash.display.sprite;
 import effects.fireeffect;
 import flash.events.mouseevent;
 import flash.net.navigatetourl;
 import flash.net.urlrequest;
 import flash.text.textfield;
 
 /**
  * ...
  * @author sliz
  */
 public class main extends sprite
 {
  public function main():void {
   addchild(new fireeffect());
   var lable:textfield = new textfield();
   lable.textcolor = 0xffffff;
   lable.selectable = false;
   lable.text = "sliz";
   lable.addeventlistener(mouseevent.click, function():void { navigatetourl(new urlrequest("/space/?534614/")); } );
   addchild(lable);
   lable.x = 370;
   lable.y = 380;
  }
 }
 
}

fireeffect.as代码

package effects
{
 import flash.display.*
 import flash.events.event;
 import flash.filters.displacementmapfilter;
 import flash.geom.*
 /**
  * ...
  * @author sliz
  */
 public class fireeffect extends sprite
 {
  private var bmd:bitmapdata;
  private var target:sprite = createsharp(400, 30,0);
  private var speed:number = math.random() * 4 + 4;
  private var strengh:number = math.random() * 60 + 60;
  private var size:number = math.random() * 17 + 20;
  private var randomseed:number = math.floor(math.random() * 10);
  private var offset:point = new point();
  private var v:point;
  private var w:number = 50;
  public function fireeffect()
  {
   addchild(target);
   addto(target);
   target.x = 0;
   target.y = 200;
  }
  private function createsharp(width:number,height:number,angle:number):sprite {
   var s:sprite = new sprite();
   s.graphics.beginfill(0, 0);
   s.graphics.drawrect( -w, -w, width + 2 * w,  w);
   s.graphics.beginfill(0xffffff);
   s.graphics.drawrect( -w, height, width + 2 * w,  w);
   var filltype:string = gradienttype.linear;
   var colors:array = [0x900000, 0x900000,0xff9900,0xfffd8a,0xffffff];
   var alphas:array = [0,1,1,1, 1];
   var ratios:array = [0x00,0xff/16,0xff*2/6,0xff*2/3, 0xff];
   var matr:matrix = new matrix();
   matr.creategradientbox(width, height, math.pi / 2);
   var spreadmethod:string = spreadmethod.pad;
   s.graphics.begingradientfill(filltype, colors, alphas, ratios, matr, spreadmethod);
   s.graphics.drawrect(0, 0, width, height);
   return s;
  }
  public function addto(target:object):void {
   bmd = new bitmapdata(target.width, target.height);
   v = new point(math.random() * (speed / 4) - speed / 8,math.random() * (speed / 4) + speed / 4 * 3);
   target.addeventlistener(event.enter_frame, update);
  }
  private function update(e:event):void {
   target.filters = [new displacementmapfilter(bmd, new point(), bitmapdatachannel.red,bitmapdatachannel.red, 10, strengh, "clamp")];
   offset=offset.add(v);
   bmd.perlinnoise(size / 2, size, 3, randomseed, false, true, 1, true, [offset, offset]);
  }
 }
 
}

热门栏目