03/15/2010 (10:54 am)
Need help optimizing my code.
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
star.lineStyle(1, 0xFFFFFF, 100);
star.moveTo(0, 100);
prev[i]=new Object()
prev[i].cx=0
prev[i].cy=0
prev[i].x=0
prev[i].y=0
place[i]=new Object()
place[i].cx=Math.random()*Stage.width/4+100
place[i].cy=Math.random()*Stage.height/4+100
place[i].x=Math.random()*Stage.width/4+100
place[i].y=Math.random()*Stage.height/4+100
}
prev[i].cx+=Math.random()*2-1
prev[i].cy+=Math.random()*2-1
prev[i].x+=Math.random()*2-1
prev[i].y+=Math.random()*2-1
prev[i].cx*=damp
prev[i].cy*=damp
prev[i].x*=damp
prev[i].y*=damp
place[i].cx+=prev[i].cx
place[i].cy+=prev[i].cy
place[i].x+=prev[i].x
place[i].y+=prev[i].y
star.lineStyle(1, 0xFFFFFF, 100);
star.moveTo(0, 100);
star.lineTo(place[i].x,place[i].y)
//star.curveTo(place[i].cx, place[i].cy, place[i].x, place[i].y);
}
var bmp = new BitmapData(Stage.width,Stage.height,true,0x00FFFFF F)
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.
Not really, I set it to 30, but teh lag is not really obvious... The problem is when, for example you have a draggable movieclip on the stage; when you move it around it had trouble keeping up to the mouse because of the lag.
#If you have any other info about this subject , Please add it free.# |