Tuesday, July 3, 2007

line width

i was creating a dashed line function which basically drew a short line, then moved on a few pixels. i was trying to display this line with one pixel width. what i discovered was that if the dash was three pixels or less in length the width would increase to two pixels.?? have a look at this flex code(which assumes a Canvas component called 'canvas'), which displays several lines with the same linestyle, but with the length of each one increasing by one pixel:

import flash.geom.*
import flash.display.*
private function drawLine():void {
  canvas.graphics.lineStyle(1,0x000000);
  for (var i:int;i<10;i++) {
    canvas.graphics.moveTo(10,(i*10));
    canvas.graphics.lineTo(10+i,(i*10));
  }
}

what's that about? well i had a look at whether other lineStyle options had any effect and discovered pixelhinting. pixelhinting is a boolean that specifies whether to hint strokes to full pixels. you'd think that a straight horizontal line wouldn't require much in the way of hinting, but the player does seem to display it incorrectly. perhaps short lines confuses it?

anyway, to resolve this issue, add pixelhinting to the lineStyle:


canvas.graphics.lineStyle(1,0x000000,1.0,true);

No comments: