Border difficulties in pygame

Advertisements

I want to make a grid in pygame and am having difficulties fixing some cosmetic issues with the grid.

I want to get rid of the thick lines on the inside of the grid because it looks wrong. I am not sure how I can do this. I have theorized that I can make the borders on the outside of the rectangle but I am not sure there is a way to do that in base pygame.

This is my code: (It is inside a function called drawGrid() with the parameter ‘gridSize’)

for x in range(0, squareSize * gridSize, squareSize):
    for y in range(0, squareSize * gridSize, squareSize):
        
        X = int(x + (700 / 2) - ((squareSize * gridSize) / 2))
        Y = int(y + (400 / 2) - ((squareSize * gridSize) / 2) + 35)
        
        rect = pygame.rect.Rect(X, Y, squareSize, squareSize)
        pygame.draw.rect(screen, outlineColor, rect, 3)

>Solution :

Simply increase the size of the rectangles by the thickness of the lines, so that the right side of one rectangle and the left side of the following rectangle and the bottom side of one rectangle and the top side of the following rectangle lie on top of each other:

for x in range(0, squareSize * gridSize, squareSize):
    for y in range(0, squareSize * gridSize, squareSize):
        
        X = int(x + (700 / 2) - ((squareSize * gridSize) / 2))
        Y = int(y + (400 / 2) - ((squareSize * gridSize) / 2) + 35)
        
        rect = pygame.rect.Rect(X, Y, squareSize + 3, squareSize + 3) # <--
        pygame.draw.rect(screen, outlineColor, rect, 3)

Leave a ReplyCancel reply