I came across this thread when trying to find out if there was a built in drawLine() function. However, I needed the width of the line to be the same regardless of angle and made this:
PHP Code:
//DrawLine( img_index, start_x, start_y, target_x, target_y, width_in_tiles, red, green, blue, alpha)
public function DrawLine( ind, sx, sy, tx, ty, wid, r, g, b, alph ) {
temp.ang = getangle(tx - sx, ty - sy) + (pi/2);
temp.wid = ( wid == NULL ? .1 : wid );
with ( findImg(ind) ) {
polygon = {
sx, sy,
tx, ty,
tx + cos(ang)*wid, ty - sin(ang)*wid,
sx + cos(ang)*wid, sy - sin(ang)*wid
};
red = ( r < 0 || r > 1 ? 0 : r );
green = ( g < 0 || g > 1 ? 0 : g );
blue = ( b < 0 || b > 1 ? 0 : b );
alpha = ( alph <= 0 || alph > 1 ? 1 : alph);
layer = 3;
}
}
An example:
PHP Code:
DrawLine(200, 25, 25, 45, 45);
//Draws a black line of width .1 tiles from 25,25 to 45,45
or if you want to specify color, width and alpha:
PHP Code:
DrawLine(200, 25, 25, 45, 45, .3, 1, 0, 0, .5);
//Draws a semi-transparent red line of width .3 tiles from 25,25 to 45,45