我知道您使用NVL(SYSTEM_HIDDEN, 'F') <> 'T'
清除所有图形但是清除了舞台上的图形,我想清除特定像素中的图形或xy值之间的图像我该怎么做?
答案 0 :(得分:7)
用图形无法做到这一点。我刚试过,画透明的形状不会创造漏洞,唉。
您应该将您拥有的图形转换为Bitmap实例并使用像素:
package
{
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
public class Holey extends Sprite
{
public function Holey()
{
super();
// Lets create some example graphics.
graphics.beginFill(0x990000);
graphics.drawCircle(200, 200, 100);
graphics.endFill();
// Convert into raster and make 1 pixel transparent.
var aBit:Bitmap = rasterize(this);
aBit.bitmapData.setPixel32(50, 50, 0x00000000);
graphics.clear();
addChild(aBit);
}
private function rasterize(source:DisplayObject):Bitmap
{
// Obtain bounds of the graphics.
var aBounds:Rectangle = source.getBounds(source);
// Create raster of appropriate size.
var aRaster:BitmapData = new BitmapData(aBounds.width, aBounds.height, true, 0x00000000);
// Make an offset to capture all the graphics.
var aMatrix:Matrix = new Matrix;
aMatrix.translate(-aBounds.left, -aBounds.top);
aRaster.draw(source, aMatrix);
return new Bitmap(aRaster);
}
}
}
答案 1 :(得分:5)
执行此操作的方法是with a mask
。使用alpha蒙版(蒙版和maskee都使用cacheAsBitmap=true
),您可以在蒙版上绘制透明像素以擦除部分。基本方法是:
将您想要通过面具影响的所有图形放在一个公共容器中(如果您的意思是所有要切割,那么它们已经在一个公共容器中: stage
或root
时间表。)
在要擦除的区域中绘制一个具有透明“孔”的位图数据对象。例如:
// fill the stage with a solid rectangle
var maskBitmapData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xff000000);
// erase part of it by drawing transparent pixels
maskBitmapData.fillRect(new Rectangle(20, 20, 200, 100), 0);
// create the mask object
var maskBitmap:Bitmap = new Bitmap(maskBitmapData);
maskBitmap.cacheAsBitmap = true; // this makes the mask an alpha mask
addChild(maskBitmap);
设置容器的.mask
property。例如,要屏蔽整个主时间轴:
root.cacheAsBitmap = true; // this makes the mask an alpha mask
root.mask = maskBitmap;
答案 2 :(得分:3)
打开堆栈溢出来回答一些问题,想想下一个小时关于如何在奶酪中放置孔......:)
您还可以将洞穴对象的blendMode属性与cacheAsBitmap
结合使用BlendMode.ERASE。这类似于蒙版,除了你实际上是绘制整体而不是它们之外的区域。
这是一个例子:
//make cheese
var cheese:Sprite = new Sprite();
cheese.cacheAsBitmap = true;
stage.addChild(cheese);
cheese.x = cheese.y = 10;
//define holes
var holes:Shape = new Shape();
holes.blendMode = BlendMode.ERASE;
cheese.addChild(holes);
//draw cheese
var g = cheese.graphics;
g.beginFill(0xFFCC00);
g.drawRect(0,0,200,150);
//**Attack chees with mices.
g = holes.graphics;
for (var i:int = 0; i < 10; i++){
g.beginFill(0xFF00FF);
var hx = Math.random()*(cheese.width-7)+7;
var hy = Math.random()*(cheese.height-7)+7;
var s = Math.random()*15;
g.drawCircle(hx, hy, s);
g.endFill();
}
结果会是这样的:
修改强>
如果将父对象的混合模式设置为cacheAsBitmap
,则不需要使用LAYER
(doc说它应该自动设置...)
因此,您可以使用cheese.blendMode = BlendMode.LAYER;
代替cheese.cacheAsBitmap = true;
。如果我没记错的话,即使使用cahceAsBitmap
混合模式,面具也不需要NORMAL
。