1

Basically i have x circles represented as MovieClips. They are all assigned the same base color (for example red). They should all have a brightness property ranging from 0 to 1 (0 would be completely white and 1 completely red).

I would like the following properties for representing these circles on stage:

  1. When the circles dont overlap they are represented as stated above.
  2. When the circles overlap the overlapping region should have the same base color as the original circles but the brightness of that area should be the sum of the brightnesses of all the circles that define the overlap.
  3. The brightness saturates at 1. So the overlap of 2 circles with brightness 0.8 is 1 (the maximum value) instead of 1.6.

I am wondering if there is some kind of BitmapFilter i could use on the circles to achieve these properties? Or am I looking in the wrong place?

I am relatively new to Actionscript so any pointers are welcome!

Antiz
  • 1,424
  • 1
  • 13
  • 20

1 Answers1

2

Hi and welcome to SO and AS3!

I'll take each point separately:

1) Quite simple, you've probably already figured out that "addChild()" will add MovieClip objects to the Display List, meaning Flash will render them every frame.

2) The easiest way to do this is through "Blend Modes", which is Adobe's way of handling overlapping display objects.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#blendMode

Try setting the .blendMode property of each circle to BlendMode.ADD:

var circle:MovieClip = new MovieClip();
circle.blendMode = BlendMode.ADD;

3) If BlendMode.ADD doesn't give you the results you want, try creating a custom shader to do the job.

http://help.adobe.com/en_US/as3/dev/WSB19E965E-CCD2-4174-8077-8E5D0141A4A8.html

IMHO Blendmode is the easiest way of achieving the desired effect, and blendShader if you want precise customization. Please comment if you have further questions!

Some tutorials and examples:

http://www.learningactionscript3.com/2007/11/03/more-properties-blendmodes-filters/

http://active.tutsplus.com/tutorials/games/introducing-blend-modes-in-flash/

Cheers,

J

Josh Mohan
  • 496
  • 6
  • 15
  • Hey, thanks for the fast reply and the warm welcome! BlendMode.ADD seems very close to what i am looking for. I see 2 problems still: 1) I think it would only work for pure Red, Green or Blue coloring. For example 0x110000 + 0x110000 = 0x220000 is a result as expected. However for 0x221100 the saturation for the Red component would start twice as fast as the saturation of the Green component which is undesired. 2) Blendmode.ADD makes the colors add up to white, which is the opposite direction of what i need, but I think simply using Blendmode.SUBSTRACT could solve that. Looking into it now. – Antiz Jul 19 '11 at 22:43
  • Have you taken a look at 'BlendMode.SCREEN' as well? Without using the default BlendMode properties you'll need to develop a shader with PixelBender: http://www.adobe.com/devnet/pixelbender.html An AS3 shader will evaluate each pixel to see if it overlaps, execute a custom set of instructions on it and return the new rgb value. – Josh Mohan Jul 19 '11 at 23:44