动作脚本3擦除绘图的问题

时间:2009-10-08 23:20:10

标签: actionscript graphics drawing erase

我在基础图像movieclip上有一个基础图像和一些精灵...用户可以使用actionscript 3中的图形api绘制一些精灵。我可以在精灵上绘制东西,但我不能创建一个像刷子一样的橡皮擦,可以去除部分不需要的图纸。我尝试使用Alpha,但没有它不起作用

我已经开始搜索它并提出解决方案:

1)Linebitmapstyle ...这个解决方案并不是最好的因为我可以移动我的精灵所以如果我使用linebitmapstyle,它会将图像中的像素绘制到精灵中,但如果精灵移动了绘制的像素,那么'改变。

2)掩蔽可能对我不起作用....

创建橡皮擦的最佳方法是什么

1 个答案:

答案 0 :(得分:3)

您可能更愿意使用位图来使这些事情更容易操作(除非您需要做可缩放的矢量图形!)。要绘制形状,您仍然可以使用图形API来创建形状。

为此,请实例化“虚拟”精灵(或其他IBitmapDrawable实现)以创建图形,然后将其“复制”到BitmapData bitmapData.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);