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,0×000000);
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,0×000000,1.0,true);

Interactive developer, Author - iOS development with Swift - book coming 2017 https://manning.com/books/ios-development-with-swift

Tagged with: ,
Posted in Flash, Flex

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: