So I am working on a platformer game for fun. I try to run the code but this error comes up:
'World' object has no attribute 'draw'
This is my world class:
class World():
def __init__(self, data):
self.tile_list = []
#load images
def draw():
dirt_img = pygame.image.load('assets/images/dirt.png')
grass_img = pygame.image.load('assets/images/grass.png')
row_count = 0
for row in data:
col_count = 0
for tile in row:
if tile == 1:
img = pygame.transform.scale(dirt_img, (tile_size, tile_size))
img_rect = img.get_rect()
img_rect.x = col_count * tile_size
img_rect.y = row_count * tile_size
tile = (img, img_rect)
self.tile_list.append(tile)
if tile == 2:
img = pygame.transform.scale(grass_img, (tile_size, tile_size))
img_rect = img.get_rect()
img_rect.x = col_count * tile_size
img_rect.y = row_count * tile_size
tile = (img, img_rect)
self.tile_list.append(tile)
col_count += 1
row_count += 1
and then I call the world.draw attribute here:
world = World(world_data)
world.draw()
Also, in case you were wondering, world_data is just a list that holds a bunch of numbers that tell the code what the world should look like.
Please help me, I have been trying to fix this for ages.