【问题标题】:Problem with actionscript 3 erasing drawingactionscript 3擦除绘图的问题
【发布时间】:2011-01-24 09:11:14
【问题描述】:

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

我已经用谷歌搜索并提出了解决方案:

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

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

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

【问题讨论】:

  • 西蒙下次你可以发布你正在工作的代码。

标签: actionscript graphics drawing erase


【解决方案1】:

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

【讨论】:

  • 我已经完成了您所说的并用我的代码进行了调整...我使用 lineTo 作为画笔但不起作用...
  • 我同意 Radu - 发布工作代码会很好。 Theo 的代码几乎完成了,但缺少一个细节:父对象的“blendMode”属性必须设置为“layer”才能进行擦除。因此,假设您将位图数据分配给 Bitmap 对象,完整的代码将是: var bitmap:Bitmap = new Bitmap(bitmapData); bitmap.blendMode = "层";
猜你喜欢
  • 2012-04-11
  • 2011-08-12
  • 2011-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多