0

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

我使用“图形”类的“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 中截取的屏幕截图,其中显示了像素:

图片

为什么三角形没有在正确的坐标中绘制?

.

.

更新:

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

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

这是我得到的结果:

结果

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

4

1 回答 1

0

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

于 2012-11-08T15:32:00.543 回答