AS3 Fire combustion Effect implementation code
Private Function Update (e:event): void {
Target.filters = [New Displacementmapfilter (BMD, New Point (), bitmapdatachannel.red,bitmapdatachannel.red, Strengh , "clamp")];
Offset=offset.add (v);
Bmd.perlinnoise (SIZE/2, size, 3, Randomseed, False, True, 1, true, [offset, offset]);
}
Main.as File Code
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 Fu Nction 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 Code
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, Strengh , "clamp")];
Offset=offset.add (v);
Bmd.perlinnoise (SIZE/2, size, 3, Randomseed, False, True, 1, true, [offset, offset]);
}
}
}