2012-11-21 88 views
2

不是一個這麼苦苦掙扎的編碼器:nextframe()上的AS3 bitmapData;

試圖在下一個幀中將當前幀作爲位圖來繪製CPU效率。在AS2中,這個代碼的作用就像一個魅力:

import flash.display.*; 
// # create the bitmap 
var tBitmapData = new BitmapData(400, 200, true, 0x00000000); 

// # now draw this movieClip's content to the bitmap 
tBitmapData.draw(this); 
// # 2nd frame should be blank! 
nextFrame(); 
// # now attach the bitmap you made to this movieclip 
this.attachBitmap(tBitmapData, 1, "auto", true); 

只需要知道如何重寫這個AS3。謝謝!

+0

應該用下面的東西替換attachBitmap行:'addChild(new Bitmap(tBitmapData));'' –

回答

1

首先,在AS3中BitmapData不是DisplayObject。您需要將其包裝到一個Bitmap對象中。然後你的addChild替換attachBitmap喬治Profenza提到:

import flash.display.*; 
// # create the bitmap 
var tBitmapData:BitmapData = new BitmapData(400, 200, true, 0x000000); 

// # now draw this movieClip's content to the bitmap 
tBitmapData.draw(this); 
// # 2nd frame should be blank! 
nextFrame(); 
// # now attach the bitmap you made to this movieclip 
this.addChild(new Bitmap(tBitmapData)); 

也嘗試鍵入您的變量(var tBitmapData:BitmapData)。這提高了性能並允許編譯器捕獲一些錯誤。