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