actionscript 3擦除图形时出现问题

actionscript 3擦除图形时出现问题,actionscript,graphics,drawing,erase,Actionscript,Graphics,Drawing,Erase,我有一个基本的图像和一些精灵的基础上图像movieclip。。。用户可以使用actionscript 3中的图形api绘制一些精灵。我可以在精灵上画东西,但我不能创建一个像橡皮擦一样的画笔来删除部分不需要的图形。我试着用Alpha,但是不行 我在谷歌上搜索了一下,找到了解决方案: 1) 线条位图样式。。。这个解决方案不是最好的,因为我的精灵可以移动,所以如果我使用linebitmapstyle,它会将像素从图像绘制到精灵,但是如果精灵移动,绘制的像素不会改变 2) 掩蔽可能对我也不起作用 创建橡

我有一个基本的图像和一些精灵的基础上图像movieclip。。。用户可以使用actionscript 3中的图形api绘制一些精灵。我可以在精灵上画东西,但我不能创建一个像橡皮擦一样的画笔来删除部分不需要的图形。我试着用Alpha,但是不行

我在谷歌上搜索了一下,找到了解决方案:

1) 线条位图样式。。。这个解决方案不是最好的,因为我的精灵可以移动,所以如果我使用linebitmapstyle,它会将像素从图像绘制到精灵,但是如果精灵移动,绘制的像素不会改变

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


创建橡皮擦的最佳方法是什么?您可能更希望使用位图使这些东西更易于操作(当然,除非您需要使用可缩放的矢量图形!)。要绘制形状,您仍然可以使用图形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);

您可能更希望使用位图使这些内容更易于操作(当然,除非您需要使用可缩放的矢量图形!)。要绘制形状,您仍然可以使用图形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);

我已经按照你说的做了,并用我的代码进行了调整。。。我使用lineTo作为画笔,但不起作用…我同意Radu的观点-发布工作代码会很好。西奥的代码几乎完成了,但缺少一个细节:父对象的“blendMode”属性必须设置为“layer”才能进行擦除。因此,假设您将位图数据分配给位图对象,完整代码将是:var bitmap:bitmap=new bitmap(bitmapData);bitmap.blendMode=“层”;我已经按照你说的做了,并用我的代码进行了调整。。。我使用lineTo作为画笔,但不起作用…我同意Radu的观点-发布工作代码会很好。西奥的代码几乎完成了,但缺少一个细节:父对象的“blendMode”属性必须设置为“layer”才能进行擦除。因此,假设您将位图数据分配给位图对象,完整代码将是:var bitmap:bitmap=new bitmap(bitmapData);bitmap.blendMode=“层”;下次你可以发布你的工作代码。下次你可以发布你的工作代码。