简体   繁体   中英

Strange behaviour when using BlendMode “erase” in flash AS3

Can any one expain how to avoid seeing lines when using BlendMode.ERASE in AS3?

Here is an example. I draw a black background to the stage and then draw 2 overlaping circles to a sprite and try to erase them from the background.

            var solidBitmapData = new BitmapData(550,400,true,0x000000);
            var mySpriteLayer = new Sprite();

            // Create black background.
            mySpriteLayer.graphics.beginFill(0x000000);
            mySpriteLayer.graphics.drawRect(0,0,550,400);
            mySpriteLayer.graphics.endFill();

            // Draw it to bitmap data.
            solidBitmapData.draw(mySpriteLayer);

            // Clear sprite.
            mySpriteLayer.graphics.clear();

            // Draw two circles
            mySpriteLayer.graphics.beginFill(0xFF0000);
            mySpriteLayer.graphics.drawCircle(200,200,50);
            mySpriteLayer.graphics.endFill();
            mySpriteLayer.graphics.beginFill(0xFF0000);
            mySpriteLayer.graphics.drawCircle(250,200,50);
            mySpriteLayer.graphics.endFill();

            // Draw circles to bitmap with blend mode erase.
            solidBitmapData.draw(mySpriteLayer,null,null,BlendMode.ERASE);

            // Create bitmap and add to stage.
            var solidBitmap = new Bitmap(solidBitmapData);
            addChild(solidBitmap);

这里显示的行

I'm talking about the lines in the middle of the circles. It seems to be something to do with linestyle but I've tried setting it to zero and the alpha to 0 but I can't get rid of the lines.

Any ideas?

You need to set cacheAsBitmap property of ' mySpriteLayer ' to ' true ' :

     mySpriteLayer.cacheAsBitmap = true;

As blend mode performs computations on pixels, it works more precisely with raster data, than with vector data.

this.blendMode = BlendMode.LAYER;

Adobe's ActionScript 3.0 Reference says about class BlendMode and field ERASE:

Erases the background based on the alpha value of the display object. This process requires that the blendMode property of the parent display object be set to flash.display.BlendMode.LAYER.

Perhaps this is the way the Sprite blend is reacting to the background. Have you tried this with two black circles on a white background? If you get the same lines (only white) you are able to conclude this is the way the blend works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM