Note that there are some explanatory texts on larger screens.

plurals
  1. POAS3 'drawPath' simple shape not drawing correctly - why?
    text
    copied!<p>I want to draw a simple triangle in ActionScript 3.</p> <p>I use the 'drawPath' method of 'Graphics' class.</p> <p>here is the code snippet:</p> <pre><code>stage.stage.quality = StageQuality.LOW; // Change quality to low so no anti-aliasing occurs var trianglePoints:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); 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.&lt;int&gt; = new Vector.&lt;int&gt;(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; </code></pre> <p>I don't know why - but instead of the triangle having points at :</p> <ul> <li>(0,0)</li> <li>(20,0)</li> <li>(20,20)</li> </ul> <p>The triangle drawn has points at :</p> <ul> <li>(0,0)</li> <li>(19,0)</li> <li>(19,19)</li> </ul> <p>Here is a <a href="http://s8.postimage.org/7npsvhvpv/alpha_Bitmap_Data_custom_draw.png" rel="nofollow noreferrer">screenshot</a> I took from Paint-Brush, with the pixels shown:</p> <p><a href="http://s8.postimage.org/7npsvhvpv/alpha_Bitmap_Data_custom_draw.png" rel="nofollow noreferrer">image http://s8.postimage.org/7npsvhvpv/alpha_Bitmap_Data_custom_draw.png</a></p> <p>Why is the triangle not drawn in the right coordinates ??</p> <p>.</p> <p>.</p> <p><strong>Upadte :</strong></p> <p>I have tried to add this line just before the 'drawPath':</p> <pre><code>currentMask.graphics.lineStyle(1, 0xFFFF0000); </code></pre> <p>and this is the <a href="http://s8.postimage.org/x6hn1g183/alpha_Bitmap_Data_custom_draw_with_line.png" rel="nofollow noreferrer">result</a> I get:</p> <p><a href="http://s8.postimage.org/x6hn1g183/alpha_Bitmap_Data_custom_draw_with_line.png" rel="nofollow noreferrer">result http://s8.postimage.org/x6hn1g183/alpha_Bitmap_Data_custom_draw_with_line.png</a></p> <p>I just can't seem to get the result I need !</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload