I’m trying to make basic lights work in my top-down 2D game (Mac, native, OpenFL 4.3.1). I have following layers (Sprites) where I draw things:
- FxLayer:Sprite (BlendMode.MULTIPLY)
- Light:Shape (BlendMode.NORMAL)
- Shade:Shape (BlendMode.NORMAL)
- other layers (BlendMode.NORMAL)
Expected result:
Result I’ve got:
When using BlendMode.NORMAL on all layers, results look identical:
Code:
...
shade.graphics.beginFill(0x888888);
shade.graphics.drawRect(0, 0, 500, 500);
shade.graphics.endFill();
shade.blendMode = BlendMode.NORMAL;
var mtx:Matrix = new Matrix();
mtx.createGradientBox(100, 100, 0, 0, 0);
light.graphics.beginGradientFill(GradientType.RADIAL, [0xffffff, 0xffffff], [1,0], [0, 255], mtx);
light.graphics.drawRect(0, 0, 100, 100);
light.graphics.endFill();
light.blendMode = BlendMode.NORMAL;
fxLayer.addChild(shade);
fxLayer.addChild(light);
fxLayer.blendMode = BlendMode.MULTIPLY;
...
If you have any ideas what am I doing wrong, please let me know. Thanks.
EDIT:
I kind of fixed it by reversing the gradient from
light.graphics.beginGradientFill(GradientType.RADIAL, [0xffffff, 0xffffff], [1,0], [0, 255], mtx);
to
light.graphics.beginGradientFill(GradientType.RADIAL, [0xffffff, 0xffffff], [0,1], [0, 255], mtx);
which looks better, but it still looks like it first multiplies with shade and then with light:
I need to merge shade and light and multiply other layers with this merged layer, i.e. centre of the light should have same lightness as left side of the image (without shade).