AS3' drawPath'简单的形状没有正确绘制 - 为什么?

时间:2012-11-08 14:41:26

标签: actionscript-3 flash graphics

我想在ActionScript 3中绘制一个简单的三角形。

我使用'Graphics'类的'drawPath'方法。

这是代码段:

stage.stage.quality = StageQuality.LOW;         // Change quality to low so no anti-aliasing occurs
var trianglePoints:Vector.<Number> = new Vector.<Number>();

trianglePoints.push(0);     trianglePoints.push(0);     // Coordinate (0,0)
trianglePoints.push(20);    trianglePoints.push(0);     // Coordinate (20,0)
trianglePoints.push(20);    trianglePoints.push(20);    // Coordinate (20,20)
trianglePoints.push(0);     trianglePoints.push(0);     // Coordinate (0,0) - tried with and without this coordinate return

var commands:Vector.<int> = new Vector.<int>(4);
commands.push(1);   // Move to
commands.push(2);   // Line to
commands.push(2);   // Line to
commands.push(2);   // Line to

var drawSprite:Sprite = new Sprite();

drawSprite.graphics.beginFill(0xFFFF0000);          // Color Red
drawSprite.graphics.drawPath(commands, trianglePoints); // Draw the path
drawSprite.graphics.endFill();

var bd:BitmapData = new BitmapData(100, 100, true, 0x0000FF00);
bd.draw(drawSprite);

var pngBytes:ByteArray = PNGEnc.encode(bd);
var fileReference:FileReference = new FileReference();
fileReference.save(pngBytes,"bd_custom_draw.png");

stage.stage.quality = StageQuality.HIGH;

我不知道为什么 - 而不是有点的三角形:

  • (0,0)
  • (20,0)
  • (20,20)

绘制的三角形有点:

  • (0,0)
  • (19,0)
  • (19,19)

这是我从Paint-Brush中获取的screenshot,其中显示了像素:

image http://s8.postimage.org/7npsvhvpv/alpha_Bitmap_Data_custom_draw.png

为什么三角形没有在右边坐标中绘制?

Upadte:

我试图在'drawPath'之前添加这一行:

currentMask.graphics.lineStyle(1, 0xFFFF0000);

这是我得到的result

result http://s8.postimage.org/x6hn1g183/alpha_Bitmap_Data_custom_draw_with_line.png

我似乎无法得到我需要的结果!

1 个答案:

答案 0 :(得分:0)

尝试currentMask.graphics.lineStyle(1,0000FFFF0000,1,true); - 将lineStyle线条粗细设置为1