Actionscript 3 使用curveTo绘图
任务是使用Actionscript 3 使用curveTo绘图,actionscript-3,apache-flex,flex4,Actionscript 3,Apache Flex,Flex4,任务是使用curveTographics方法绘制自定义形状 问题是路径连接并不精确 结果是: <fx:Script> <![CDATA[ import mx.events.FlexEvent; protected function application1_creationCompleteHandler(event:FlexEvent):void { // TODO Auto-generated
curveTo
graphics方法绘制自定义形状
问题是路径连接并不精确
结果是:
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
test.graphics.clear();
test.graphics.lineStyle(1);
drawBorder(test.graphics, 200, 200);
}
private function drawBorder(g: Graphics, width: Number, height: Number): void
{
var cornerRadius: int = 20;
var pointerWidth: int = 4;
var pointerHeight: int = 10;
var pointerBottomGap: int = 6;
width -= pointerWidth;
g.moveTo(0, height - cornerRadius);
g.lineTo(0, cornerRadius + 1);
g.curveTo(0, 0, cornerRadius, 0);
g.lineTo(width - cornerRadius, 0);
g.curveTo(width, 0, width, cornerRadius);
var pointerY: int = height - pointerHeight - pointerBottomGap;
g.lineTo(width, pointerY);
g.lineTo(width + pointerWidth, pointerY + pointerHeight);
g.lineTo(width - pointerWidth, pointerY + pointerHeight + 1);
g.curveTo(width - pointerWidth, height, width - cornerRadius, height);
g.lineTo(cornerRadius, height);
g.curveTo(0, height, 0, height - cornerRadius);
}
]]>
</fx:Script>
<mx:UIComponent
id="test"
x="100" y="100"/>
问题可以重新表述-如何使用
curveTo
方法绘制具有角半径的rect?如果您指的是奇数消除混叠,请尝试启用像素暗示:
targetSprite.graphics.lineStyle(1.0, 0x000000, 1.0, true);
增加线条笔划权重的厚度将有所帮助;此外,请尝试指定封口和接头:
import flash.display.CapsStyle;
import flash.display.JointStyle;
import flash.display.LineScaleMode;
graphics.lineStyle(2,
0x0,
1.0,
true,
LineScaleMode.NORMAL,
CapsStyle.SQUARE,
JointStyle.MITER);
drawBorder(graphics, 200, 200);
我想这是一种锻炼?因为使用原语绘制这样的基本形状要容易得多。不,这是真正的任务。这是聊天信息的设计,所以需要调整大小。如何使用基本体达到这种状态?据我所知,形状由一个圆形矩形和左下角的一个小三角形组成。也就是说,如果它需要可伸缩性,你将很难将三角形保持在正确的位置。你可能会更好地使用它。我看看是否能转换你的代码。我不知道如何调整路径大小。路径可能类似于'M 10 50 L 10 100…',因此值是硬编码的。这很有帮助。结果是好的。会更好吗?比较。第一个图像-
像素暗示
为真,第二个为假;是的,增加厚度有帮助,但我不能改变它,因为设计。