1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Draw changing number of rectangles [SOLVED]

Discussion in 'Programming' started by Yahl, Oct 27, 2016.

  1. Yahl

    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.
     
  2. stainedofmind

    stainedofmind Member

    Joined:
    Jun 20, 2016
    Posts:
    701
    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...).
     
  3. Yahl

    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.
     
  4. DariusWolfe

    DariusWolfe Member

    Joined:
    Sep 23, 2016
    Posts:
    32
    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.
     
    Yahl likes this.
  5. Yahl

    Yahl Guest

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

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice