ActionScript 3 删除绘图的问题

发布于 2024-08-07 16:42:21 字数 333 浏览 2 评论 0原文

我有一个基础图像和一些位于 basd 图像 movieclip 之上的精灵...用户可以使用 actionscript 3 中的图形 api 绘制一些精灵。我可以在精灵上绘制内容,但无法创建橡皮擦就像画笔一样,可以删除部分不需要的图画。我尝试使用Alpha,但不,它不起作用

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

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

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

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

I have a based image and some sprites on top of the basd image movieclip... Some of the sprites can be drawn by the user using graphics api in actionscript 3. I can draw things on the sprites but I can't create an eraser like brush that can remove part of the unwanted drawings. I try using Alpha but no it doesn't work

I have googled about it and come up with the solution:

1) Linebitmapstyle... This solution is not the best one coz I my sprites can be moved so if I use linebitmapstyle, it does draw the pixel from the image to the sprite but if the sprite moved the drawn pixel won't change.

2) Masking may not work for me either....

What is the best way of creating the eraser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心在旅行 2024-08-14 16:42:21

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

为此,请实例化一个“虚拟”精灵(或另一个 IBitmapDrawable 实现)来创建图形,然后将它们“复制”到 bitmapData.draw 的 BitmapData 中。 () 函数。这样,您可以使用选项 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);

You may rather want to use a Bitmap to make such things easier to manipulate (unless you need to do scalable vector graphics of course!). To draw shapes you can still use the graphics API to create the shapes.

To do so, instantiate a "dummy" sprite (or another IBitmapDrawable implementation) to create the graphics and then "copy" them to the BitmapData the bitmapData.draw() function. This way you can for instance draw with the option BlendMode.ERASE in order remove the pixels of the shape.

Example (from the top of my mind) :

// 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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文