문제

is it possible to align the stroke of a graphic with actionscript? for example, the following code creates a black rounded rect with a grey stroke that is automatically centre aligned.

var t:Sprite = new Sprite();
t.graphics.lineStyle(5, 0x555555);
t.graphics.beginFill(0, 1);
t.graphics.drawRoundRect(25, 25, 200, 75, 25, 25);
t.graphics.endFill();

the lineStyle function doesn't seem to offer any built-in functionality for aligning the stroke. in Adobe Illustrator, you can align a stroke to be either centre (half in/half out of the fill), inside (bordering within the fill) or outside. (bordering outside the fill).

도움이 되었습니까?

해결책

This is not supported in Flash (even in the GUI). You would have to modify the drawRoundRect parameters to simulate this effect.

var strokeWidth:Number = 5;
var strokeAlign:String = 'outer';
var t:Sprite = new Sprite();
t.graphics.lineStyle(strokeWidth, 0x555555);
t.graphics.beginFill(0, 1);
if (strokeAlign == 'outer') {
    t.graphics.drawRoundRect(25 - strokeWidth / 2, 25 - strokeWidth / 2, 200 + strokeWidth, 75 + strokeWidth, 25 + strokeWidth / 2, 25 + strokeWidth / 2);
} else if (strokeAlign == 'inner') {
    t.graphics.drawRoundRect(25 + strokeWidth / 2, 25 + strokeWidth / 2, 200 - strokeWidth, 75 - strokeWidth, 25 - strokeWidth / 2, 25 - strokeWidth / 2);
} else {
    t.graphics.drawRoundRect(25, 25, 200, 75, 25, 25);
}
t.graphics.endFill();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top