0

The lines won't show up on the screen for some reason.

Here's what I've tried

class Grid(Sprite):
    def __init__(self):
        self.grid = pygame.Surface(size)
        self.grid.set_colorkey((0,0,0))

    def draw(self):
        # DRAW TILE LINES ----------------------------------------------------------
        grid_x = 0
        grid_y = 0
        for i in range(GRID_SIZE):
            pygame.draw.aaline(self.grid,BLACK,[grid_x,UPPER_BOUNDARY],[grid_x,LOWER_BOUNDARY],1)
            pygame.draw.aaline(self.grid,BLACK,[LEFT_BOUNDARY,y],[RIGHT_BOUNDARY,grid_y],1)
            grid_x += TILE_SIZE
            grid_y += TILE_SIZE
        # tile test
        pygame.draw.rect(screen,BLACK,(49*TILE_SIZE,34*TILE_SIZE,TILE_SIZE,TILE_SIZE))
        screen.blit(self.grid,(0,0))

Creating the object:

grid = Grid()

Calling class: (in main program loop)

grid.draw()
Alexdr5398
  • 51
  • 1
  • 6

2 Answers2

0

You need to pass your draw function a screen instance. Otherwise your blitting it to nothing.

def draw(self, screen):
    #...

Also remember to call pygame.display.update() in your main loop. If you have any questions just comment below. Good luck!

Remolten
  • 2,614
  • 2
  • 25
  • 29
  • He is blitting the lines onto the Grid surface, and later blitting the Grid onto the screen. This is correct. I think display.update() is the issue – Bartlomiej Lewandowski Apr 05 '14 at 17:34
  • I figured this out last night. It was just a dumb mistake. The colour key was set to (0,0,0) and the lines were BLACK. – Alexdr5398 Apr 05 '14 at 19:49
0

You probably lack a pygame.display.update() call in your main loop.

I see you have created an object that is a Grid. Since your grid does not change, you could draw the lines once onto the grid, and then only blit the grid onto the main screen in the main loop.

class Grid(Sprite):
    def __init__(self):
        self.grid = pygame.Surface(size)
        self.grid.set_colorkey((0,0,0))
        self.createGrid()

    def createGrid(self):
        grid_x = 0
        grid_y = 0
        for i in range(GRID_SIZE):
            pygame.draw.aaline(self.grid,BLACK,[grid_x,UPPER_BOUNDARY],[grid_x,LOWER_BOUNDARY],1)
            pygame.draw.aaline(self.grid,BLACK,[LEFT_BOUNDARY,y],[RIGHT_BOUNDARY,grid_y],1)
            grid_x += TILE_SIZE
            grid_y += TILE_SIZE

    def draw(self,screen):
        pygame.draw.rect(screen,BLACK,(49*TILE_SIZE,34*TILE_SIZE,TILE_SIZE,TILE_SIZE))
        screen.blit(self.grid,(0,0))
Bartlomiej Lewandowski
  • 10,771
  • 14
  • 44
  • 75