Search code examples
pythonimagepygame

How can I draw images and sprites in Pygame?


How can I draw images using Pygame? I know how to load them.

I have made a blank window.

When I use screen.blit(blank, (10,10)), it does not draw the image and instead leaves the screen blank.


Solution

  • This is a typical layout:

    myimage = pygame.image.load("myimage.bmp")
    imagerect = myimage.get_rect()
    
    while 1:
        your_code_here
    
        screen.fill(black)
        screen.blit(myimage, imagerect)
        pygame.display.flip()