• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Help with Drawing a grid using a sprite...

ReikonMage

Member
Hello,
I have been trying to make a tactical Rpg game similar to Final Fantasy tactics or Devil Survivor. But drawing a grid using a sprite is providing me troubles. In context, I have a sprite that I made to resemble the grid. The code I have should draw the sprite-like a grid when it hits the collision box. But it just draws it diagonally and ignores the IF rule I put. I looked all over the internet for someone who had the same problem but no avail. Each cell should be 64x64
Here is the code in a Script I have
Code:
if (Selected){       // Selected is a bool I have for when a character is selected
    for(var i=0; i<= max(room_height, room_width); i+=64) {
if place_meeting(x,y,CgroundO){  // CgroundO is a Object collision box that the grid should draw on top of.
    draw_sprite(GridSpr,1,i,i);
}}}
 
Last edited:

FrostyCat

Redemption Seeker
You are iterating over two dimensions, use a nested loop.
GML:
for (var i = 0; i <= room_width; i += 64) {
    for (var j = 0; j <= room_height; j += 64) {
        if (place_meeting(x, y, Cground0) {
            draw_sprite(GridSpr, 1, i, j);
        }
    }
}
 

ReikonMage

Member
You are iterating over two dimensions, use a nested loop.
GML:
for (var i = 0; i <= room_width; i += 64) {
    for (var j = 0; j <= room_height; j += 64) {
        if (place_meeting(x, y, Cground0) {
            draw_sprite(GridSpr, 1, i, j);
        }
    }
}
That was very helpful Thank you, I forgot Nested Loops were a thing
 
Top