2009-10-08 34 views
0

我有一個基礎的圖像和一些精靈在基礎圖像動畫片上...一些精靈可以由用戶使用圖形API在動作3中繪製。精靈,但我不能創建一個像刷子一樣的橡皮擦,可以刪除部分不需要的圖紙。我嘗試使用阿爾法,但沒有它不工作問題與動作3擦除繪圖

我用Google搜索一下,並拿出瞭解決方案:

1)...調用lineBitmapStyle該解決方案是不是最好的怎麼我我的精靈可以移動所以如果我使用linebitmapstyle,它確實將圖像中的像素繪製到精靈,但如果精靈移動繪製的像素不會改變。

2)屏蔽可能不適合我的工作要麼....

什麼是創造橡皮擦

+0

西門下一次你可以發佈你的工作代碼。 – 2011-01-24 16:37:32

回答

3

你可能更願意使用一個位圖,使這樣的事情更易於操作的最佳方式(除非你需要做可伸縮的矢量圖形當然!)。要繪製形狀,您仍然可以使用圖形API創建形狀。

要做到這一點,實例化一個「虛擬」精靈(或其他IBitmapDrawable實現)創建圖形,然後「複製」他們在BitmapDatabitmapData.draw()功能。通過這種方式,您可以使用選項BlendMode.ERASE進行繪製,以便去除形狀的像素。

例(從我的腦海的頂部):

// creates a bitmap data canvas 
var bitmapData:BitmapData = new BitmapData(500, 500); 

// creates a bitmap display object to contain the BitmapData 
addChild(new Bitmap(bitmapData)); 

// creates a dummy object to draw and draws a 10px circle 
var brush:Sprite = new Sprite(); // note this is not even added to the stage 
brush.graphics.beginFill(0xff0000); 
brush.graphics.drawCircle(10, 10, 10); 

// the matrix will be used to position the "brush strokes" on the canvas 
var matrix:Matrix = new Matrix(); 

// draws a circle in the middle of the canvas 
matrix.translate(250, 250); 
bitmapData.draw(brush, matrix 

// translates the position 5 pixels to the right to slightly erase the previously 
// drawn circle creating a half moon    
matrix.translate(5, 0); 
bitmapData.draw(brush, matrix,null,BlendMode.ERASE); 
+0

我已經完成了你已經告訴並用我的代碼進行了調整...我用lineTo作爲畫筆,但不起作用... – LittleFunny 2009-10-09 04:14:37

+0

現在它可以工作..謝謝... – LittleFunny 2009-10-09 04:54:25

+0

很好,沒問題。 – 2009-10-09 08:53:00