1

I want to replace this draw rectangle function, and instead let it produce an image.

Rectangle Function:

pygame.draw.rect(pygame.display.set_mode((800,600)), black, [0,0, 100, 100])

Looking for something on the lines of this:

pygame.draw.image(**coordinatesX**, **coordinatesY**, **imagefile.jpg**)
  • This link might help: http://stackoverflow.com/questions/8873219/what-is-a-good-way-to-draw-images-using-pygame – Jerrybibo Mar 12 '17 at 04:06
  • 6
    Possible duplicate of [What is a good way to draw images using pygame?](http://stackoverflow.com/questions/8873219/what-is-a-good-way-to-draw-images-using-pygame) – Jerrybibo Mar 12 '17 at 04:06

2 Answers2

1

To load an image, you need the file stored, and you load it using:

pygame.image.load('example.png')

Now your code should look like:

pygame.image.load('example.png')

pygame.display.set_mode((800, 600))
Community
  • 1
  • 1
HQ220
  • 43
  • 6
0

so first you have to load the image using image = pygame.image.load() and then use screen.blit(image) to draw it on the screen. For this to work you should define the screen at the beginning not in the draw function like you have done above. Just screen = pygame.display.set_mode((800,600)) should work.

Pyrolle
  • 51
  • 1
  • 6