Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Border difficulties in pygame

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

This is what it looks like

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading