Objects are not drawn and the display appears in black

0

I'm using Pygame but I can not get my objects to draw correctly. I do not get any errors and the application responds correctly. The objects are displayed correctly in the console (with print ), only the display appears black.

This is my code:

def draw_enviroment(blobs):
    game_display.fill(WHITE)
    for blob_id in blobs:
        blob = blobs[blob_id]
        pygame.draw.circle(game_display, blob.color, [blob.x, blob.y],     blob.size)
        blob.move()
    pygame.display.update()


def main():
    blue_blobs = dict(enumerate([Blob(BLUE, i) for i in     range(STARTING_BLUE_BLOBS)]))
    print(blue_blobs)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

    draw_enviroment(blue_blobs)
    clock.tick(60)


if __name__ == "__main__":
    main()
    
asked by guille 15.07.2017 в 18:33
source

1 answer

0

As I told you just as you have the function main the last two lines of it never get to run.

Within your infinite cycle you have your cycle for to respond to events. The infinite cycle only comes out when the pygame.QUIT event is generated, which means leaving the application. So both the line responsible for drawing the objects, and the delay between frames never get to run.

Both lines must be inside the mainloop ( while True ) just after the cycle for events and not outside:

def main():
    blue_blobs = dict(enumerate([Blob(BLUE, i) for i in     range(STARTING_BLUE_BLOBS)]))
    print(blue_blobs)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        draw_enviroment(blue_blobs)
        clock.tick(60)
    
answered by 15.07.2017 в 19:35