Hi,i just read a code and there is an enumerate function but i don't know what enumerate do?I read some question and it appear that enumerate is giving index for each loops but if i delete the enumerate it give me an error so i think there are some things that i missed.
Here the error:
too many values to unpack(expected 2)
And here here the code:
def load_tile_table(filename, width, height):
image = pygame.image.load(filename).convert()
image_width, image_height = image.get_size()
tile_table = []
for tile_x in range(0, image_width//width):
line = []
tile_table.append(line)
for tile_y in range(0, image_height//height):
rect = (tile_x*width, tile_y*height, width, height)
line.append(image.subsurface(rect))
return tile_table
if __name__ == '__main__':
pygame.init()
screen = pygame.display.set_mode((128,98))
screen.fill((255, 255, 255))
table = load_tile_table('ground.png', 24, 16)
for x, row in enumerate(table):
for y,tile in enumerate(row):
screen.blit(tile, (x*32, y*24))
pygame.display.flip()
while pygame.event.wait().type != pygame.locals.QUIT:
pass
Thank you very much