1

I'm in the middle of creating a platformer game similar to Mario, I have a level ready and sprites that decorate the level. Right now I am just trying to display the level as grey tiles in my game window with the draw method:

self.terrain_sprites.draw(self.display_surface)

but it isn't working, it's just displaying a black screen. Does anyone know the solution to fix this? Any help will be appreciated.

import pygame
from support import import_csv_layout
from settings import tile_size
from tiles import Tile

# setup for the level
class Level:
    def __init__(self,level_data,surface):
        self.display_surface = surface

        terrain_layout = import_csv_layout(level_data['terrain'])
        self.terrain_sprites = self.create_tile_group(terrain_layout,'terrain') # to let python know that we need the terrain files

    def create_tile_group(self,layout,type):
        sprite_group = pygame.sprite.Group()

        for row_index, row in enumerate(layout):
            for col_index,val in enumerate(row):
                if val != '-1':
                    x = col_index * tile_size
                    y = row_index * tile_size

                    if type == 'terrain':
                        sprite = Tile(tile_size,x,y)
                        sprite_group.add(sprite)

        return sprite_group

    def run(self):
        # runs the entire game / level
        self.terrain_sprites.draw(self.display_surface)
Nicholas Obert
  • 1,235
  • 1
  • 13
  • 29
kruz_19
  • 11
  • 1
  • 1
    What is that `surface` argument you are passing in? Can you show the code that calls the `Level.__init__()` function? Also, you may use a debugger (or print statements) to verify at runtime that functions like `import_csv_layout()` or `create_tile_group` actually return what you expect. – Nicholas Obert Jul 21 '22 at 08:50
  • Are you calling `pygame.display.update()`? A [mcve] will make it easier to help you. – import random Jul 21 '22 at 08:50
  • 90% of the time when something is not displaying it's because you forgot to call `pygame.display.upate()`/`pygame.display.flip()` – mousetail Jul 21 '22 at 09:02
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jul 21 '22 at 16:21

0 Answers0