GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2009-12-05 09:16:14

Sonica
Member
Registered: 2009-12-03
Posts: 2

draw_rectangle_toalpha(x1,y1,x2,y2,colour,xscale,yscale)

This script draws a gradient rectangle, with the specified colour to 0 alpha... Take a look:

Expand/*
**  Usage:
**      draw_rectangle_toalpha(x1,y1,x2,y2,colour,xscale,yscale)
**
**  Arguments:
**      x1,y1       first corner of the rectangle
**      x2,y2       second corner of the rectangle
**      colour      the colour of the visible side (optional)
**      xscale      direction of the gradient
**      yscale      direction of the gradient
**
**  Returns:
**      nothing
**
**  Notes:
**      Draws a rectangle of a cirtain colour, which
**      will have a gradient and turn to invisible.
**
**  GMLscripts.com
*/
{
    //initialize some variables to use
    var x1,y1,x2,x2,width,height,alpha,alphastep;
    x1=argument0
    y1=argument1
    x2=argument2
    y2=argument3
    width=(x2-x1)
    height=(y2-y1)
    alpha=1
    alphastep=(1/width)
    draw_set_color(argument4)

    //move along and draw the line, decreasing alpha each time
    if argument5=1 && argument6=1{
        for ( i = x1; i < x2; i += 1 ){
            draw_set_alpha(alpha)
            draw_line(i,y1,i,y2)
            alpha-=alphastep
        }
    }

    if argument5=-1 && argument6=1{
        for ( i = x2; i > x1; i -= 1 ){
            draw_set_alpha(alpha)
            draw_line(i,y1,i,y2)
            alpha-=alphastep
        }
    }


    if argument5=1 && argument6=-1{
        for ( i = y1; i < y2; i += 1 ){
            draw_set_alpha(alpha)
            draw_line(x1,i,x2,i)
            alpha-=alphastep
        }
    }

    if argument5=-1 && argument6=-1{
        for ( i = y2; i > y1; i -= 1 ){
            draw_set_alpha(alpha)
            draw_line(x1,i,x2,i)
            alpha-=alphastep
        }
    }
}

Last edited by Sonica (2009-12-06 07:30:55)

Offline

#2 2009-12-05 10:31:11

Marchal_Mig12
Member
Registered: 2009-05-21
Posts: 75

Re: draw_rectangle_toalpha(x1,y1,x2,y2,colour,xscale,yscale)

Primitives would bemuch faster though.

Offline

#3 2009-12-06 07:27:06

Sonica
Member
Registered: 2009-12-03
Posts: 2

Re: draw_rectangle_toalpha(x1,y1,x2,y2,colour,xscale,yscale)

Hmm, I have never used primitives, and I never had the idea... I will look into it

Offline

#4 2009-12-06 21:13:30

Marchal_Mig12
Member
Registered: 2009-05-21
Posts: 75

Re: draw_rectangle_toalpha(x1,y1,x2,y2,colour,xscale,yscale)

Sonica wrote:

Hmm, I have never used primitives, and I never had the idea... I will look into it

Here's an example of what can be done. It shouldn't require a script though. It could simply be used in the draw event and consequently be faster.

Expandvar x1,y1,x2,y2,c1,c2,c3,c4,a1,a2,a3,a4;
x1 = argument0;
y1 = argument1;
x2 = argument2;
y2 = argument3;
c1 = argument4;
c2 = argument5;
c3 = argument6;
c4 = argument7;
a1 = argument8;
a2 = argument9;
a3 = argument10;
a4 = argument11;


draw_primitive_begin(pr_trianglestrip);
draw_vertex_color(x1,y1,c1,a1);
draw_vertex_color(x2,y1,c2,a2);
draw_vertex_color(x1,y2,c4,a4);
draw_vertex_color(x2,y2,c3,a3);
draw_primitive_end();

Last edited by Marchal_Mig12 (2009-12-06 21:13:54)

Offline

Board footer

Powered by FluxBB