Gw Temp

Menu

Tutorial - 'GM Transparent Line Script' by Guest

An item about Gamemaker posted on

Blurb

A gamemaker tutorial that shows you how to draw translucent lines.

Body

Uses software alpha blending to draw a partially transparent line in GM. I am pretty sure it works in the unregistered version.

Here are the instructions:

1. It only works with one object, so you either need to use duplicate code (a little more memory from the arrays) or make it into global statements.

2. Create these two scripts:

trans_line():
//arg0:x1
//arg1:x2
//arg2:y1
//arg3:y2
//arg4:transparency (0-255), 1 is all transparent, 255 is totally solid
//arg5:line color
x1=argument0
y1=argument1
x2=argument2
y2=argument3
n=argument4
linecolor=argument5
if x2 d1=point_distance(x1,y1,x2,y2)
increment=1
for (i=d2;i {
x3=i
if x2-x1=0 {x2+=0.1}
y3=(x3-x2)*(y2-y1)/(x2-x1)+y2
brush_color=get_alpha(linecolor,draw_getpixel(x3,y3),n)
draw_pixel(x3,y3)
}

get_alpha():
{
return make_color((ATable[argument0 & 255,argument2])+(ATable[argument1 & 255,255-argument2]),(ATable[(argument0 & 65280) / 256,argument2])+(ATable[(argument1 & 65280) / 256,255-argument2]), (ATable[(argument0 & 16711680) / 65536,argument2])+(ATable[(argument1 & 16711680) / 65536,255-argument2]))
}

//alpha code obtained with help from Ramirez

3. The object the executes the code must execute this in its create event:


for (i=0; i<256; i+=1) {
for (i2=0; i2<256; i2+=1) {
ATable[i,i2] = (i*i2>>8);
}
}

4. Just use this script to draw the line:


trans_line(x1,x2,y1,y2,alpha,line color):

(see the script for more infor)

Line color must be used by making a color through inputting the rgb values or by using the built in c_blue, c_red, etc

Here is a GMD that shows the script in action:


http://www.geocities.com/grfuor4150@sbcglobal.net/transparentline.zip

copy and paste it into the address bar


If the line appears separated (like it is dashed) you must decrease the value for increment in the trans_line() script, but I think it should work ok.