Legacy GM Draw changing number of rectangles [SOLVED]

Y

Yahl

Guest
So I'm working on a menue, facing the problem of drawing multiple rectangles. I want them to be drawn in a row, but the number of them wouldn't be the same all time (based on a variable).

As "repeat" doesn't work very well in draw events, I wonder if there is a better option of drawing dynamic numbers of rectangles from only one instance.
 
Repeat works just fine in every event. Not sure where you got that idea from. Anyway, quick example:

Code:
var num_rect = 10, // Number of rectanges to draw
    spacing = 8, // How many pixels apart to draw the rectangles
    width = 16, // Width of the rectangles
    height = 16, // Height of the rectangles
    x1 = x; // Counter for where to draw each rectangle

repeat (num_rect)
{
    draw_rectangle(x1, y, x1 + width - 1, y + height - 1, false);
   
    x1 += width + spacing;
}
... And of course, you'll have to supply your own values for the various variables (what an odd sentence...).
 
Y

Yahl

Guest
Thank you for your quick answer, but that's exactly what I tried. It just draws the rectangles one after another and make them disappear again.
 

DariusWolfe

Member
I use something like this:

for (i=0;i<v_number;i++)
{
draw_rectangle(x+v_offset*i,y,x+v_width+v_offset*i,y+v_height)
}

this will draw v_number rectangles starting at x,y with a width and height of v_width and v_height, with an offset from point of origin of v_offset.

Edit: Note that if v_offset is not equal to or greater than v_width, you'll get overlapping rectangles.
 
Y

Yahl

Guest
Thank you! This works just fine and offers all I was looking for!
 
Top