What I wanted to do was draw multiple lines comming from the same point to a random point that moves around randomly. I then wanted to apply a blur filter. The effect produces a ray of light that resembles what you would see if you where underwater. It’s pretty cool, but after a while I found that the lag got worse (I think it was because of the huge “for” loop) anyway… I decided to convert all the lines to a bitmapdata and THEN apply a filter to it… This did take care of the growth in lag… But instead… It is now always in a constant lag that doesn’t change much.
Can anyone give me any tips on how I could optimize my code further or have I reached flash 8’s max potential in terms of performance?
K thx, here’s the code:
import flash.filters.BlurFilter;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
center = new Object();
center.x = Stage.width/2;
center.y = Stage.height/2;
firstRun=true
num=100
damp = .95;
this.createEmptyMovieClip("star", this.getNextHighestDepth());
var prev=new Array()
var place=new Array()
blur=new BlurFilter(20,20,1)
this.createEmptyMovieClip("bmpHolder", this.getNextHighestDepth());
this.onEnterFrame = function () {
star.clear()
for (var i=0; i<num; i++) {
if(firstRun){
star.lineStyle(1, 0xFFFFFF, 100);
star.moveTo(0, 100);
prev*=new Object()
prev*.cx=0
prev*.cy=0
prev*.x=0
prev*.y=0
place*=new Object()
place*.cx=Math.random()*Stage.width/4+100
place*.cy=Math.random()*Stage.height/4+100
place*.x=Math.random()*Stage.width/4+100
place*.y=Math.random()*Stage.height/4+100
}
prev*.cx+=Math.random()*2-1
prev*.cy+=Math.random()*2-1
prev*.x+=Math.random()*2-1
prev*.y+=Math.random()*2-1
prev*.cx*=damp
prev*.cy*=damp
prev*.x*=damp
prev*.y*=damp
place*.cx+=prev*.cx
place*.cy+=prev*.cy
place*.x+=prev*.x
place*.y+=prev*.y
star.lineStyle(1, 0xFFFFFF, 100);
star.moveTo(0, 100);
star.lineTo(place*.x,place*.y)
//star.curveTo(place*.cx, place*.cy, place*.x, place*.y);
}
var bmp = new BitmapData(Stage.width,Stage.height,true,0x00FFFFFF)
bmp.draw(star)
star.clear()
//bmp.applyFilter(bmp,new Rectangle(0,0,Stage.width,Stage.height),new Point(0,0),blur)
bmp.applyFilter(bmp,new Rectangle(0,0,Stage.width,Stage.height),new Point(0,0),blur)
bmpHolder.attachBitmap(bmp,1)
if(firstRun){
firstRun=false
}
};
turtle_mc.swapDepths(this.getNextHighestDepth());
P.S. You will need a dark background to see the light rays.