Hello to all,
I would like to create a white outer outline around a grid.
This grid has empty cells.
Especially on the edges (see image below).

The problem is that the code tests if the box to the left of it is empty
condition
if (y > 0 && Grille[l, m - 1] == -1)
To draw my outline, let’s start with the left outer edge.
You have to draw a vertical line of 1.6f per box, only if the box on the left is empty.
For that, I use the following code:
void Start()
{
for (int i = -1; i < Lignes + 1; i++)
for (int j = -1; j < Colonnes + 1; j++)
{
Grille[i, j] = -1;
}
for (int i = 0; i < Lignes; i++)
for (int j = 0; j < Colonnes; j++)
{
Grille[i, j] = 0;
}
Grille[0, 0] = -1;
Grille[6, 4] = -1;
Grille[1, 1] = -1;
Grille[6, 0] = -1;
Grille[6, 6] = -1;
Grille[4, 4] = -1;
Grille[3, 3] = -1;
Grille[4, 4] = -1;
CreateGrid();
}
The problem is that the code makes the lines disappear.
This way we test if the boxes are empty or not.
And here is an image to better understand the code:

In short, my question is the following: how to draw an outline around a grid (0.2f thick) which has empty cells (see image at the top of the message).
Thanks for your help,
A+
Hello! I think you’ve posted the code you use to set up the grid, but not the code you are using to check & draw the lines.
But your approach sounds correct - for each cell, check the neighbouring cells in each direction and draw a line if the cell is empty, since it must be an edge.
The problem is that the initialization doesn’t work.
I have created an array (int Grid ). With an outline of cells worth -1 and the center at 0.
In order to test if a cell is empty (left, right, top or bottom).
Here is the code in image:

However, I have entered the following code:
void Start()
{
for (int i = -1; i < Lignes + 1; i++)
for (int j = -1; j < Colonnes + 1; j++)
{
Grille[i, j] = -1;
}
for (int i = 0; i < Lignes + 1; i++)
for (int j = 0; j < Colonnes + 1; j++)
{
Grille[i, j] = 0;
}
Grille[2, 3] = -1;
Grille[6, 4] = -1;
Grille[1, 1] = -1;
Grille[6, 6] = -1;
Grille[4, 4] = -1;
CreateGrid();
}
void CreateGrid()
{
for (int x = -Lignes / 2; x < Lignes / 2; x++)
for (int y = -Colonnes / 2; y < Colonnes / 2; y++) // left edge
{
int l = x + Lignes / 2;
int m = y + Colonnes / 2;
if (Grille[l, m] != -1) continue;
if (y > 0 && Grille[l, m - 1] == -1) continue;
Vector3 startPos = new Vector3((x - 1) * LINE_SCALE, 0, y * LINE_SCALE);
Vector3 endPos = new Vector3((x - 1) * LINE_SCALE, 0, (y + 1) * LINE_SCALE);
CreateLine(contour.transform, Color.white, 2f, startPos, endPos);
}
}
But it does not work.
Indeed when I compile, my grid and the lines disappear.
Your help is welcome
If someone could help me to draw the lines on the left outer edge,
his help is welcome.
Thank you for your help,
A+
int l = x + Lignes / 2;
int m = y + Colonnes / 2;
Do you need to +1 to these variables? Don’t they equal the same as x & y?
Finding it a bit hard to follow the way you are looping through the grid. If you want to centre it onscreen, you could just offset each line by a constant Vector3 instead of having to divide your line and column count by 2 (what happens if the grid size is odd?)
I personally would make this simpler. Make the int[,] size the exact number of rows and columns you want including the edges. Then loop through each cell in the grid, checking the 4 neighbours. If the row or column index is out of the bounds of the grid, skip it.