GameMaker draw_rectangle Set the Outline Width ?

Zhanghua

Member
It's only 1px with outline of "draw_rectangle", So how can I set the border width for this function?
TKS.
 

obscene

Member
Unfortunately there is no built-in way to do this. I looked to see if someone had a custom script for this and couldn't seem to find one. You could write one yourself without too much trouble using draw_line_width(x1, y1, x2, y2, w) which will draw a thick line.... you just need to draw 4 of them.
 

Zhanghua

Member
Unfortunately there is no built-in way to do this. I looked to see if someone had a custom script for this and couldn't seem to find one. You could write one yourself without too much trouble using draw_line_width(x1, y1, x2, y2, w) which will draw a thick line.... you just need to draw 4 of them.
thank you for confirming the drawback...I will consider the line...
 
I

Immy42

Guest
This is way too late, but I made a script to do this, may aswell put it here. Script works as follows:

drawRectangle(0,0,32,16,c_blue,16)
- Draws a blue rectangle, 32x16 in size, with outline that has width of 16 pixels, draws the outline thickness either from the edges outward.

Code:

GML:
//drawRectangle(x1,y1,x2,y2,color,width)



x1 = argument0

y1 = argument1

x2 = argument2

y2 = argument3



color = argument4

width = argument5



draw_set_color(color)

draw_rectangle(x1,y1,x2,y2,true)

var i = 0

do
{

    i += 1

    draw_rectangle(x1-i,y1-i,x2+i,y2+i,true)

}
until(i = width)
 
Last edited by a moderator:

TheZampo

Member
This is way too late, but I made a script to do this, may aswell put it here. Script works as follows:

drawRectangle(0,0,32,16,c_blue,16)
- Draws a blue rectangle, 32x16 in size, with outline that has width of 16 pixels, draws the outline thickness either from the edges outward.

Code:

GML:
//drawRectangle(x1,y1,x2,y2,color,width)



x1 = argument0

y1 = argument1

x2 = argument2

y2 = argument3



color = argument4

width = argument5



draw_set_color(color)

draw_rectangle(x1,y1,x2,y2,true)

var i = 0

do
{

    i += 1

    draw_rectangle(x1-i,y1-i,x2+i,y2+i,true)

}
until(i = width)
Not too late for me!
Very helpful, save me a lot of time =).
 
draw_rectangle tends to be pretty slow, and that method would be calling it for each pixel of width that you need. So if you are drawing lots of these thick rectangles, you are probably better off using 4 draw_sprite_ext's. Just use a 1x1 pixel sprite and stretch it as wide/long as you need it for each edge of the rect.

Just noticed this thread is from 2017 lol.
 

FoxyOfJungle

Kazan Games
While you're talking about it, I have to inform you that the latest Game Maker Studio 2 update has Nine Slices, which makes the use of draw_rectangle() unnecessary. You can use a rectangle any way you like and stretch it.
 

RockstarCRO

Member
This is way too late, but I made a script to do this, may aswell put it here. Script works as follows:

drawRectangle(0,0,32,16,c_blue,16)
- Draws a blue rectangle, 32x16 in size, with outline that has width of 16 pixels, draws the outline thickness either from the edges outward.

Code:

GML:
//drawRectangle(x1,y1,x2,y2,color,width)



x1 = argument0

y1 = argument1

x2 = argument2

y2 = argument3



color = argument4

width = argument5



draw_set_color(color)

draw_rectangle(x1,y1,x2,y2,true)

var i = 0

do
{

    i += 1

    draw_rectangle(x1-i,y1-i,x2+i,y2+i,true)

}
until(i = width)
Yup! Still years later helping out!!! Thanks.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Foxy has a point about nineslices, though. All vector drawing (draw_rectangle, draw_line and so on) will have lines that are 1 screen pixel thick, and for fullscreen games on larger screens this will be very thin and can look weird next to stretched sprites whose outline thickness is 1 room pixel. Plus there's some inconsistency on if the far coordinate ends at the beginning or the end of the pixel, so you can get a 1 pixel "bleed" past where you wanted drawing to end if you mix different drawing functions. Both issues are very annoying if you want pixel perfect low rez retro games... but by drawing sprites for everything you can get around that really easily.
 
Top