AS3 'drawPath' simple shape not drawing correctly - why?

0

I want to draw a simple triangle in ActionScript 3.

I use the 'drawPath' method of 'Graphics' class.

here is the code snippet:

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;

I don't know why - but instead of the triangle having points at :

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

The triangle drawn has points at :

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

Here is a screenshot I took from Paint-Brush, with the pixels shown:

image

Why is the triangle not drawn in the right coordinates ??

.

.

Upadte :

I have tried to add this line just before the 'drawPath':

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

and this is the result I get:

result

I just can't seem to get the result I need !

actionscript-3
flash
graphics
asked on Stack Overflow Nov 8, 2012 by John Miner • edited Aug 26, 2019 by Glorfindel

1 Answer

0

Try currentMask.graphics.lineStyle(1, 0xFFFF0000,1,true); - setting the lineStyle line thickness to 1

answered on Stack Overflow Nov 8, 2012 by Gone3d

User contributions licensed under CC BY-SA 3.0