View Single Post
  #13  
Old 01-06-2011, 01:31 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by 12171217 View Post
Also doesn't take into account the direction of the line. Again, needs trig.
Sales made one a while back.


Quote:
Originally Posted by salesman View Post
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 
__________________
Reply With Quote