draw_rectangle

Draws a rectangle.

Syntax:

GML Code Example

draw_rectangle(x1, y1, x2, y2, outline);


Argument Description
x1 The x coordinate of the top left corner of the rectangle.
y1 The y coordinate of the top left corner of the rectangle.
x2 The x coordinate of the bottom right corner of the rectangle.
y2 The y coordinate of the bottom right corner of the rectangle.
outline Whether the rectangle is drawn filled (false) or as a one pixel wide outline (true).


Returns: N/A


Description

With this function you can draw either an outline of a rectangle or a filled rectangle where the (x1,y1) position is the top left corner and the (x2,y2) position is the bottom right corner.


Example:

GML Code Example

draw_set_colour(c_yellow);
 draw_rectangle(100, 100, 300, 200, true);
 

This will draw a rectangle outline, with its top left corner at (100,100) and its bottom right corner at (300,200).





These examples are submitted by the community. Upvote the examples you think are most helpful.

Random Filled Rectangles and With Edges by /u/tmcicuurd12b42 on January 20, 2017

GML Code

///draw event

for(var i = 0; i<100; i++)
{
    //get random position for from and to coords
    var x1 = random(room_width);
    var y1 = random(room_height);
    var x2 = random(room_width);
    var y2 = random(room_height);
    //set white (c_white)
    draw_set_color($FFFFFF);
    //draw filled
    draw_rectangle(x1, y1, x2, y2, false);
    //set black (c_black)
    draw_set_color($000000);
    //draw border
    draw_rectangle(x1, y1, x2, y2, true);
}
/*
See It In Action:
https://yal.cc/r/gml/?mode=undefined&lzgml=MQEwpgZglgdmAEBbAhrAUAeg-WUAu8AxgPbjwAWYATmGmqJLAgM55gAOm2AruyMmyKkElGnQbQ48EFWQB3LtNlyhZUbSwYZ8+GABuYGHjoRiVABR7kVHPAC88AAwBuHAB4AjI5c4A1L4BKNABvNHhw+CwAczACWRgQYkR4dmJmfChiGHhTGwgqJPhkBPg8YiEzEGYwiKsbAA8Pe3h4xMRzAqSAfTkoEDxyAOca8Lr4AE8mh1akjuJuyigo8jwhkfgx+oAmZpn2zsQevoG1iI3rCZ3p4ra5hbAlldOIrGZY+DlyfARzQh6vthBM7aORdN54LokAA2ZnMABIAGJI5HPcJYEE5KBQqFgEDrEFdGiEPDFKI48yNAA0Ew81O21PGW2pEGQULeqMiGHB8AARlDkIQANbwX5dPkCwVAiIE8GQ4gwixw7zKxwc9HKXmVaj45SEsDE0nkqk0ulMy7UvBUbhgNYAXzoQA
*/

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here