Question

This is a very basic question I ran into when drawing with AS. Let's say I have the following code.

g.lineStyle(20, 0xff0000, 1, false);
g.moveTo(10, 10);
g.lineTo(210, 10);   

Because the line thickness is 20. This will actually draw a line as a rectangle from (0,0) to (220, 20). i.e. thickness/2 will get added in each dimension.

I wanted to know if: 1. This is correct or I got it wrong? 2. So every time we need to draw line where we don't want it to be bound within something e.g. drawing an inside border we need to take this into account so the line would not go outside a particular an area. Is that also correct?

Was it helpful?

Solution

Yes, 1) is correct. With regards to 2) actually getRect() method will not take stroke width in account. Here is a code:

stop();

var mc:MovieClip = new MovieClip();

var gr:Graphics = mc.graphics;


//Draw a rectangle 50x50
gr.lineStyle(20);
gr.beginFill(0, 0.5);
gr.drawRect(0, 0, 50, 50);
gr.endFill();

this.addChild(mc);

//Will trace (x=0, y=0, w=50, h=50)
trace(mc.getRect(this));

//Will trace (x=-10, y=-10, w=70, h=70)
trace(mc.getBounds(this));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top