Ben
Ben

Reputation: 2045

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);

Lines shown here

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?

Upvotes: 4

Views: 4402

Answers (3)

Engineer
Engineer

Reputation: 48793

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.

Upvotes: 6

André Staltz
André Staltz

Reputation: 13994

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.

Upvotes: 1

Brooks Hanes
Brooks Hanes

Reputation: 425

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.

Upvotes: 0

Related Questions