Reputation: 1474
When drawing multiple shapes on a Graphics object in Actionscript intersections cancel eachother out.
Is there any way to disable this default behaviour?
I could simple use the beginFill() and endFill() methods in between drawing shapes. The problem with this approach for me would be that each of the shapes will 'blend together' whenever i set the value of the alpha property to anything other then 1.
Basically what I want is 1 solid drawing consisting of different shapes (circles for example), so that when the alpha value is changed the different parts of this drawing should not become visible.
The following approaches did not work:
-2 circles are drawn but the intersection is cancelled out
var solidShape = new Sprite();
solidShape.graphics.beginFill(0xFF0000)
solidShape.graphics.drawCircle(0,0,100)
solidShape.graphics.drawCircle(0,50,100)
solidShape.graphics.endFill()
-2 circles are drawn correctly, but they become visible when i change the alpha value
var solidShape = new Sprite();
solidShape.graphics.beginFill(0xFF0000)
solidShape.graphics.drawCircle(0,0,100)
solidShape.graphics.endFill()
solidShape.graphics.beginFill(0xFF0000)
solidShape.graphics.drawCircle(0,50,100)
solidShape.graphics.endFill()
solidShape.alpa = 0.5
Upvotes: 0
Views: 166
Reputation: 3794
Easiest way would be to draw each shape in a separate DisplayObject, like so:
var shapes:Sprite = new Sprite();
var shape:Shape = new Shape();
shape.graphics.beginFill(0xFF0000);
shape.graphics.drawCircle(0,0,100);
shapes.addChild(shape);
shape = new Shape();
shape.graphics.beginFill(0xFF0000);
shape.graphics.drawCircle(0,50,100);
shapes.addChild(shape);
shapes.alpha = 0.5;
shapes.blendMode = "layer";
If you're trying to do it with a single object (like a user drawn shape that intersects itself), RC's answer will suit your needs much better.
Upvotes: 1
Reputation: 595
Flash determines which parts of the drawing are inside of the filled zone with its 'winding rules'. In this case, the paths created for the circles both go in the same direction, which makes them cancel out.
If you use the Advanced Drawing API, you can change the winding rules. Unfortunately, that also means you lose the convenience of the drawCircle method, and you'll have to use curves instead.
Here's a guide that might help you get started with the Advanced Drawing API.
Upvotes: 1