flash - Using bitmap data to draw massive image -


i making snow boarding game in as3. problem having want leave trail in snow behind board.

i have had think , feel best way of achieving use lineto() method draw line form snowboards previous position current position. if of way down slope end line 23000 pixels long seems extremely large , have major impact on performance.

if convert trail movieclip bitmap improve performance? targeting minimum of flash player 9 have found have issues when handling bmp's on 2880 pixels think method might not work.

can think of clean , fast solution?

thanks in advance

you store few values in fixed length vector/array , keep updating single value while shifting others (so bit 'out of date'):

var ptsnum:int = 25; var pts:vector.<point> = new vector.<point>(ptsnum,true); for(var i:int = 0 ; < ptsnum ; i++) pts[i] = new point(mousex,mousey); this.addeventlistener(event.enter_frame, update);  function update(event:event):void{     //update     for(var i:int = 0 ; < ptsnum-1 ; i++) pts[i] = pts[i+1];     pts[ptsnum-1] = new point(mousex,mousey);     //draw     graphics.clear();     graphics.moveto(pts[0].x,pts[0].y);     for(i = 0 ; < ptsnum ; i++){         graphics.linestyle(i,0,i/ptsnum);         graphics.lineto(pts[i].x,pts[i].y);     } } 

i'm using 2 loops in update split updating drawing, it's easy understand. of course, can use single loop if wish, or use foreach() shift, you.

trail

if want draw trail bitmapdata, can redraw rectangle(or shape of boarder) bitmapdata, , use colormatrix fade:

var sw:int = stage.stagewidth,sh:int = stage.stageheight; var bd:bitmapdata = new bitmapdata(sw,sh,false,0); var pmouse:point = new point();//previous mouse position var zero:point = new point(); var fade:colormatrixfilter = new colormatrixfilter([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0]);//alpha 0.95 var r:shape = new shape();r.graphics.beginfill(0x009900,0.9);r.graphics.drawrect(-10,-15,20,30);//a tall rect addchild(new bitmap(bd)); addeventlistener(event.enter_frame, update);  function update(event:event):void{     r.x = mousex;     r.y = mousey;     r.rotation = math.atan2(mousey-pmouse.y,mousex-pmouse.x) * 57.2957795;//rotate mouse     pmouse.x = mousex;     pmouse.y = mousey;     bd.draw(r,r.transform.matrix);//draw rect @ it's current position     bd.applyfilter(bd, bd.rect, zero, fade);//apply alpha colormatrix } 

trail alpha

hth


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -