• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GMS 2.3+ [Solved] Grid Generation Code Not Printing All Lines

Storm1208

Member
Hey all! I've been working on some grid creation code and I ran into an issue with it last night. I've been trying to fix it for the past day but I haven't had any luck.

The code is supposed to generate a 5x8 size grid within the screen (not based on the room's height and width, but within a section of the room itself). Here's a look at the code from my grid objects draw event:

GML:
//drawing columns
for(var  i = obj_gridorigin.x; i < obj_gridorigin.x + (grid_width * (col + 1)); i += grid_width){
    draw_line_width(i, obj_gridorigin.y, i, obj_gridorigin.y + (grid_height * row), line_width);
}

//drawing rows
for(var  i = obj_gridorigin.y; i < obj_gridorigin.y + (grid_width * (row + 1)); i += grid_height){
    draw_line_width(obj_gridorigin.x, i, obj_gridorigin.x + (grid_width * col), i, line_width);
}
(obj_gridorigin is an object physically placed in the room to track the origin point (top-left corner) of the grid itself)

I ran this code using GameMaker's debugger and the "i" value of both loops hits every position it's supposed to, but for some reason not all the lines get printed. Here's a picture of what this code generates in-game:
funkygrid.PNG
I've tried looking up other threads and debugging my code but I can't figure out why some of the row and column lines just aren't printing. I'd appreciate some insight!
 

DaveInDev

Member
could it be a problem of window stretching that makes the lines disappear "between two pixels" ? maybe try to increase the line_width to 15 and retry.
(or maybe more than 15, because we do not see the real w/h of your window....)

Could be the case if your room_size is really greater than your window size.
 

Storm1208

Member
could it be a problem of window stretching that makes the lines disappear "between two pixels" ? maybe try to increase the line_width to 15 and retry.
(or maybe more than 15, because we do not see the real w/h of your window....)

Could be the case if your room_size is really greater than your window size.
Ah, that was it! I changed the line_width and it looks like everything was actually printing after all!
solvedgrid.PNG
To remedy this in the future should I try and ensure the room size and window size are equal? I think what you said about the room_size being greater than the window size was true.
 

DaveInDev

Member
To remedy this in the future should I try and ensure the room size and window size are equal?
Yes, at least for an immediate solution to your problem, if you want to keep any thin line of 1 pixel visible.
But you should investigate camera and view points : you can have a very large room, but focus only on a part of this room.
The room is just the world. You can then view only one part of the world and move your camera around.

So it all depends on your game : you can have a room size twice the size of you window : some games are even zooming in and out, so that this ratio is always changing.
But you must understand that in that case, some pixels can be missing...
Usually in these forums and with GMS2, people, who wants to get a "big-pixel" old type game, prefers to do the contrary : have a viewport (camera) smaller than the window, so that they obtain a pixelate effect.
 
Top