Question

UPDATE It appears this happens with any blendmode - not just erase

I've been working on a crude lighting engine for a game of mine in Adobe AIR, written in pure AS3. How it works is there is a bitmap data the size of the screen, and at the beginning of each frame it is set to a black transparent rectangle. During that step, things can subtract from the bitmap data and then when it is drawn on the screen those areas will appear lighter.

Setting that up and everything has gone smoothly. Currently I'm messing around with a basic radial gradient from the light source, and setting that up was pretty easy

_circ.graphics.lineStyle();
_circ.graphics.beginGradientFill(GradientType.RADIAL, [0x000000, 0x000000], [.9, 0], [0, 255]);
_circ.graphics.drawCircle(0, 0, 100);
_circ.graphics.endFill()

Then to draw (well, anti-draw) it onto the bitmap data, I just do this

FP.matrix.identity();
FP.matrix.tx = x + 30;
FP.matrix.ty = y + 5;
WorldGame.darkBit.draw(_circ, FP.matrix, null, BlendMode.ERASE, null, true);
FP.matrix.identity();

FP.matrix is just a generic global matrix (I'm using Flashpunk). Now this ALMOST works, except for one tiny problem.

bad things

If you look very closely you'll be able to see a very thin black line going around the gradient, which is so very frustrating. I have no idea what's causing it - I've tried making the gradient smaller than the circle, I've tried making it linear, tried making it a different colour. It doesn't happen on blend modes other than ERASE as well, and as far as I can tell, it doesn't happen to non-gradients either (still erasing).

Any suggestions?

Was it helpful?

Solution

Strange behaviour when using BlendMode "erase" in flash AS3

Somehow I missed this in my earlier searching, guess I didn't use the right keywords. The solution is just to set bitmap caching to true on the sprite that is being used as the "eraser". For example:

_circ.cacheAsBitmap = true;

And that's all there is to it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top