你可以存儲幾個值的固定長度矢量/陣列和不斷更新的單個值,而轉向其他的(所以他們有點「過時」):
var ptsNum:int = 25;
var pts:Vector.<Point> = new Vector.<Point>(ptsNum,true);
for(var i:int = 0 ; i < 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 ; i < 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 ; i < ptsNum ; i++){
graphics.lineStyle(i,0,i/ptsNum);
graphics.lineTo(pts[i].x,pts[i].y);
}
}
我在更新中使用兩個for循環只是爲了將更新從圖形中分離出來,因此很容易理解。當然,如果你願意的話,你可以使用一個for循環,或者使用類似forEach()的變化,直到你。
如果你想畫一個線索的一個BitmapData,您可以重新繪製一個矩形(或你的邊界的形狀)到BitmapData,並使用嘉洛斯的褪色:
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 to mouse
pMouse.x = mouseX;
pMouse.y = mouseY;
bd.draw(r,r.transform.matrix);//draw the rect at it's current position
bd.applyFilter(bd, bd.rect, zero, fade);//apply the alpha colorMatrix
}
HTH
你並不需要繪製23000個像素。無論如何,用戶不會看到23000像素。 – 2011-02-18 15:28:39