Strange behavior when using BlendMode to β€œerase” in AS3 flash

Can anyone find out how to avoid viewing rows when using BlendMode.ERASE in AS3?

Here is an example. I draw a black background on the scene, and then I draw 2 overlapping circles for the 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 am talking about lines in the middle of circles. Something seems to be related to linestyle, but I tried setting it to zero and alpha to 0, but I can't get rid of the lines.

Any ideas?

+4
source share
3 answers

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

  mySpriteLayer.cacheAsBitmap = true; 

Because the blend mode performs pixel-based calculations, it works more accurately with raster data than with vector data.

+6
source
 this.blendMode = BlendMode.LAYER; 

The Adobe ActionScript 3.0 Reference describes the BlendMode class and the ERASE field:

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

+1
source

Perhaps this is how the Sprite mix responds to the background. Have you tried this with two black circles on a white background? If you get the same lines (white only), you can conclude that this is the way the mixture works.

0
source

Source: https://habr.com/ru/post/1403094/


All Articles